-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path13fibonacci.py
More file actions
30 lines (23 loc) · 889 Bytes
/
Copy path13fibonacci.py
File metadata and controls
30 lines (23 loc) · 889 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
"""
Write a program that asks the user how many Fibonnaci 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 Fibonnaci seqence 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 fibonnaci():
length = int(input("Generate a Fibonacci sequence. Enter how many numbers:\n> "))
fib_list = []
if length <= 2:
for i in range(length):
fib_list.append(1)
else:
fib_list.append(1)
fib_list.append(1)
for i in range(length):
fib_list.append(fib_list[-2] + fib_list[-1])
for item in fib_list:
print(item)
fibonnaci()