Implement a fibonacci function which calculates the nth number of the fibonacci sequence.

def fib(n):  if n <= 1:    return n  else:    return(fib(n-1) + fib(n-2))
This is the code for a very basic version. This coud be used to explain how recursion works thanks to a relatively easy example.

AF

Related Python Mentoring answers

All answers ▸

What is the difference between a cycle "if" and "while"?


Write a short program to print all the even numbers 1 to 100


What is Object-Oriented Programming?


What is the difference between DFS and BFS? Where can I apply each?