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 ▸

How do I use format python code?


How might we implement the bubble sort algorithm in Python


What's the difference between a local and a global variable?


Make a program that asks the user for a series of numbers until they either want to output the average or quit the program.