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
PostgreSQLv16

Εδώ θα εμφανιστεί το αποτέλεσμα εκτέλεσης του κώδικα

Visible tests
1
Input
0
Expected0
2
Input
1
Expected1
3
Input
10
Expected55
4
Input
20
Expected6765
5
Input
2
Expected1
6
Input
30
Expected832040
Focus radio
Paused · SomaFM · Fluid