-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProgram-15.py
More file actions
17 lines (17 loc) · 857 Bytes
/
Program-15.py
File metadata and controls
17 lines (17 loc) · 857 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
# Write a program that asks the user how many Fibonacci numbers to generate and then generates them. Take this opportunity to think about how you can use functions. Make sure to ask the user to enter the number of numbers in the sequence to generate. (Hint: The Fibonacci sequence is a sequence of numbers where the next number in the sequence is the sum of the previous two numbers in the sequence. The sequence looks like this: 1, 1, 2, 3, 5, 8, 13, ...)
def fibonacci():
num = int(input("Please enter how many numbers would you like in your Fibonacci sequence: \n"))
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())