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.

Answered by Atom F. Python tutor

1192 Views

See similar Python Mentoring tutors

Related Python Mentoring answers

All answers ▸

What are docstrings and how do I use them to improve my code readability?


Explain the difference between local and global variables


How could I write a program to convert Km/h to m/s in python


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


We're here to help

contact us iconContact usWhatsapp logoMessage us on Whatsapptelephone icon+44 (0) 203 773 6020
Facebook logoInstagram logoLinkedIn logo
Cookie Preferences