86.6k views
0 votes
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.

User Oddy
by
6.0k points

1 Answer

3 votes

Answer:

The program written in Python is as follows

def fibonac(N):

series = ""

for i in range(0,N+1):

series = series + str(i) + ","

return series[:-1]

N = int(input("Number: "))

print(fibonac(N))

Step-by-step explanation:

This line defines the function fibonac

def fibonac(N):

This line initializes variable "series" to an empty string

series = ""

This line iterates through the passed argument, N

for i in range(0,N+1):

This line determines the Fibonacci sequence

series = series + str(i) + ","

Lastly, this line returns the Fibonacci sequence

return series[:-1]

The main starts here

The firs line prompts user for input

N = int(input("Number: "))

This line prints the Fibonacci sequence

print(fibonac(N))

User Ratique
by
4.7k points