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 could I write a program to convert Km/h to m/s in python


Write a Python script to take a product name as input and then automatically google search reviews for it and open the top 3 search results in different tabs


How do I check if a number is prime using a python program?


What is Object-Oriented Programming?