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

Related Computing A Level answers

All answers ▸

Outline the differences between how a compiler and an interpreter works, and explain the advantages and usage of of each [12 marks]


What is the decimal equivalent of the following sequence of bits, which represents an unsigned binary integer: 1101001. What is the decimal equivalent if the sequence in bits encodes a two’s complement binary integer.


How do I make simplifying Boolean algebra easier?


A computer stores floating point numbers of size 1 byte, with 3 bits for the mantissa and 5 bits for the exponent. State what the effects would be on the stored numbers if instead 5 bits were used for the mantissa and 3 bits were used for the exponent.