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)

Answered by Meer S. Computing tutor

1061 Views

See similar Computing A Level tutors

Related Computing A Level answers

All answers ▸

A binary, 8-bit floating point number 0111 0010 is said to have a 4-bit mantissa and a 4-bit exponent. What is meant by the terms 'mantissa' and 'exponent'? What is the value of this 8-bit binary floating point number?


Project Euler Question 3: What is the largest prime factor of the number 600851475143?


Taken from an AQA paper: A common misconception is that the Internet is the World Wide Web. Explain the differences between the Internet and the World Wide Web.


How to represent a negative decimal number using 8-bit binary two's complement ?


We're here to help

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

© MyTutorWeb Ltd 2013–2024

Terms & Conditions|Privacy Policy