Skip to content

Commit 20222fb

Browse files
authored
Add files via upload
1 parent 1772b91 commit 20222fb

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

Fibonacci.py

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
# Write a program that asks the user how many Fibonnaci
2+
# numbers to generate and then generates them. Take this
3+
# opportunity to think about how you can use functions.
4+
# Make sure to ask the user to enter the number of numbers
5+
# in the sequence to generate
6+
7+
def gen_fib(length, mylist = []):
8+
if(len(mylist) < 2):
9+
mylist.append(1)
10+
else:
11+
mylist.append(mylist[len(mylist)-1] + mylist[len(mylist)-2])
12+
13+
if(len(mylist) == length):
14+
return mylist
15+
else:
16+
return gen_fib(length, mylist)
17+
18+
print(gen_fib(int(input("How many numbers of the Fibonacci sequence would you like to generate?\n"))))

0 commit comments

Comments
 (0)