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

1801 Views

See similar Python Mentoring tutors

Related Python Mentoring answers

All answers ▸

What is the outcome of the following code? print(2*[3,4,5])


Using the shared code editor, write a recursive function for calculating a factorial of an input parameter.


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


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


We're here to help

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

MyTutor is part of the IXL family of brands:

© 2026 by IXL Learning