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 check if a number is prime using a python program?


Write a function that takes a list of numbers as input, and outputs the average of the numbers. The function should catch any errors.


What is the difference between a for loop and a while loop.


Create a program that takes in two numbers and returns the highest of the two