Write a recursive function to return the nth Fibonacci number in Python

def fibonacci(n): if n <= 1: return n else: return fibonacci(n-1) + fibonacci(n-2)

FG
Answered by Finn G. Python tutor

1505 Views

See similar Python Mentoring tutors

Related Python Mentoring answers

All answers ▸

How do I use for loops in Python?


Describe both For-loops and While-loops and explain how you can simulate the effect of a for loop with a while loop with an example.


Write a short program to print all the even numbers 1 to 100


Write a recursive function that takes any integer n and prints the nth Fibonacci number.


We're here to help

contact us iconContact ustelephone icon+44 (0) 203 773 6020
Facebook logoInstagram logoLinkedIn logo

© MyTutorWeb Ltd 2013–2025

Terms & Conditions|Privacy Policy
Cookie Preferences