233k views
2 votes
Python: Write a program that asks the user how many Fibonnaci numbers to generate and then generates them.

User Scheintod
by
4.0k points

1 Answer

7 votes

Answer:

k (btw I kind of suck at python I use a lot of c++ but this is the best I can make up)

Explanation: def fibonacci():

num = int(input("Please enter how many numbers would you like in your Fibonacci sequence: "))

i = 1

if num == 0:

fib = []

elif num == 1:

fib = [1]

elif num == 2:

fib = [1,1]

elif num > 2:

fib = [1,1]

while i < (num - 1):

fib.append(fib[i] + fib[i-1])

i += 1

return fib

print (fibonacci())

input()

User Srakyi
by
3.4k points