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 Object-Oriented Programming?


Write a function s(n) that will return a list of the first n squares.


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


Write a basic program to output the lowest of 3 input numbers. (You may omit error checks on your inputs)