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 ▸

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


Manually implement a function that finds the smallest value in a list of integers and print it.


What is Object-Oriented Programming?


What does __init__ mean?