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 the difference between a for loop and a while loop.


Create an rock, paper, scissors game. The user should input one option, and the computer should play randomly.


Explain how you would write a python program that takes a rectangle and a point in a 2D space as command-line arguments and checks if they intersect.


Create an algorithm that can be used as a guessing game. Make sure to import random at the start.