In Python, write a recursive function that returns the first n Fibonacci numbers.

Begin by denoting the first and second Fibonacci number as 0 and 1 respectively. This helps us define a base case for our algorithm. We know that new Fibonacci numbers are formed by adding its 2 predecessors. This will help us define the recursive call.
Code:def Fibonacci(n): if n == 0: return 0 elif n == 1: return 1 else: return Fibonacci(n-1)+Fibonacci(n-2)

MS
Answered by Meer S. Computing tutor

1607 Views

See similar Computing A Level tutors

Related Computing A Level answers

All answers ▸

why is the Harvard architecture is sometimes used in preference to the von Neumann architecture and give examples of each system


Write pseudocode for the binary search algorithm and state, with an explanation, it's worst case complexity in big-O notation


What is the difference between simplex, half duplex and full duplex?


What are the main differences between different loops when it comes to coding ?


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