fibonacci/fibo.py

22 lines
436 B
Python
Raw Normal View History

2022-04-29 09:31:15 +03:00
# Fibonacci number generator in Python using recursion
import time
COUNT = 30
def fibo(i):
if i <= 1:
return i
else:
return(fibo(i-1) + fibo(i-2))
def main():
print("Lasketaan fibo: %d" % COUNT)
start_time = time.time()
for x in range(COUNT):
print("Fibo: %2d = %d" %(x, fibo(x)))
print("Laskenta kesti %.5f sec" % (time.time() - start_time))
if __name__ == '__main__':
main()