Returns a list of all the even terms in the Fibonacci sequence that are less than n.
(n)
| 1 | def fib(n): |
| 2 | """ |
| 3 | Returns a list of all the even terms in the Fibonacci sequence that are less than n. |
| 4 | """ |
| 5 | ls = [] |
| 6 | a, b = 0, 1 |
| 7 | while b < n: |
| 8 | if b % 2 == 0: |
| 9 | ls.append(b) |
| 10 | a, b = b, a+b |
| 11 | return ls |
| 12 | |
| 13 | if __name__ == '__main__': |
| 14 | n = int(input("Enter max number: ").strip()) |