r/PythonLearning • • 5d ago

school

def fib(n):

if n <= 1:

return n

return fib(n - 1) + fib(n - 2)

n = int(input("Количество чисел: "))

for i in range(n):

print(fib(i), end=" ")

0 Upvotes

10 comments sorted by

View all comments

2

u/PureWasian 5d ago

Thanks for sharing?

Note that you can make this more efficient with memoization. Otherwise you're repeating a lot of function call calculations, which makes the time complexity a lot worse: O( 2n ) instead of O(n)