Question: Codio 6.5 Codio Python Challenge Activity The Fibonacci Sequence is the series of numbers: 0, 1, 1, 2, 3, 5, 8, 13, 21, 34, The
Codio 6.5 Codio Python Challenge Activity
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! We will pass in a value N. Write a program that outputs the complete Fibonacci sequence for N iterations. Important: If N is 0, then we expect to get an output of 0. If N=1 then we expect 0, 1 etc.
I have come up with the following code so far, but it's not returning the 2nd "1" as part of the required output. I'm sure it's something super small, but not sure what's missing? Here's my code:
# Get N from the command line
import sys N= int(sys.argv[1])
# Your code goes here
print('0') n1 = 1 n2 = 2 if N > 0: if N > 1: print('1') for i in range(2, N): print(n2) temp = n2 n2 += n1 n1 = temp
What am I missing?
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
