Question: Fibonacci Python Need help with my code to get the required output. Thank you. Task: The Fibonacci Sequence is the series of numbers: 0, 1,
Fibonacci Python
Need help with my code to get the required output. Thank you.
Task:
The Fibonacci Sequence is the series of numbers:
0, 1, 1, 2, 3, 5, 8, 13, 21, 34,
The next number is found by adding up the two numbers before it.
We start of with 0 and 1
The first 1 in the above list is found by adding the previous 2 numbers (0+1)
The 2 is found by adding the two numbers before it (1+1)
Similarly, the 3 is found by adding the two numbers before it (1+2),
And the 5 is (2+3)
and so on!
# Get N from the command line import sys N= int(sys.argv[1])
# Your code goes here
n1 = 1 n2 = 2 if N > 0: if N > 1: print('0', '') print('1', '') print('1', '') for i in range(2, N): print('' + str(n2), '') temp = n2 n2 += n1 n1 = temp
My Output:
Your Program Output: 0 1 1 2 3 5 8 13 21
Your output was incorrect. Try again.
Expected Output: 0 1 1 2 3 5 8 13 21
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
