mirror of
https://github.com/TheAlgorithms/Python.git
synced 2025-01-19 00:37:02 +00:00
p2 sol2 fixed (#669)
This commit is contained in:
parent
8d4d95099f
commit
16e95a3de5
|
@ -1,12 +1,15 @@
|
||||||
def fib(n):
|
def fib(n):
|
||||||
a, b, s = 0, 1, 0
|
"""
|
||||||
|
Returns a list of all the even terms in the Fibonacci sequence that are less than n.
|
||||||
|
"""
|
||||||
|
ls = []
|
||||||
|
a, b = 0, 1
|
||||||
while b < n:
|
while b < n:
|
||||||
if b % 2 == 0 and b < n: s += b
|
if b % 2 == 0:
|
||||||
|
ls.append(b)
|
||||||
a, b = b, a+b
|
a, b = b, a+b
|
||||||
ls.append(s)
|
return ls
|
||||||
|
|
||||||
T = int(input().strip())
|
if __name__ == '__main__':
|
||||||
ls = []
|
n = int(input("Enter max number: ").strip())
|
||||||
for _ in range(T):
|
print(sum(fib(n)))
|
||||||
fib(int(input().strip()))
|
|
||||||
print(ls, sep = '\n')
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user