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 can be used to iterate through a list in python?


With the help of Pandas and Numpy library create a DataFrame with the columns "Name", "Surname", "Age" and "Gender", create as many rows as you want. Print out the result.


Write a simple number guessing game, give the user 3 tries to guess a number between 1 and 10


Print "Hello World!" ten times without typing (or pasting) the print function more than once