Fibonacci by Position
Fibonacci numbers are a classic way to practice loops, recursion, and dynamic programming. The function fib receives n and returns the n-th Fibonacci number: fib(0) is 0, fib(1) is 1, and each next value is the sum of the two previous ones. Be careful with the indexing: the sequence starts from zero.
Примеры
Ввод
0Вывод
0Ввод
1Вывод
1Ввод
10Вывод
55Нужно реализовать
def fib(n):
Теги
dprecursionmath
Prijavi se da vidiš povijest predaja
PrijavaPrijavi se da koristiš AI mentora
PrijavaVisible tests
1
Input
0Expected
02
Input
1Expected
13
Input
10Expected
554
Input
20Expected
67655
Input
2Expected
16
Input
30Expected
832040Focus radio
Paused · SomaFM · Fluid