This code calculates, from a list of integers, the next fibonacci number for each integer. It does this for the first 60 numbers in the sequence. Any pointers on improving computing time, code readability, etc. are what I'm looking for.
def getFib(limit):
a = 1
b = 1
res = [a, b]
for i in range(1, limit):
temp = a
a = b
b = temp + b
res.append(b)
return res
def nextFibonacci(fib, n):
for x in n:
if x < 1 or x > fib[len(fib)-1]:
print("Value is out of range.")
else:
temp = x
for c in fib:
if c > temp:
temp = c
break
print(temp)
def main():
listMe = [1, 9, 22]
fib = getFib(60)
nextFibonacci(fib, listMe)
if __name__ == "__main__":
main()
27000000000000
not give me27777890035288
? \$\endgroup\$ – 301_Moved_Permanently Sep 4 '17 at 11:16>
. (I mean, after the second for loop,temp
would be13
[resp.34
] forx = 9
[resp.x = 22
] whereas8
[resp.21
] would be a closer fit.) \$\endgroup\$ – 301_Moved_Permanently Sep 4 '17 at 11:29