forked from MrBlaise/learnpython
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfibonacci.py
More file actions
35 lines (24 loc) · 767 Bytes
/
fibonacci.py
File metadata and controls
35 lines (24 loc) · 767 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
31
32
33
34
35
#!/usr/bin/env python3
# Fibonacci Sequence Generator
# Have the user enter a number and
# generate a fibonacci sequence
# which size is equivalent to that number.
def fibSequence(n):
"""
Generates a fibonacci sequence
with the size of n
"""
assert n > 0
series = [1]
while len(series) < n:
if len(series) == 1:
series.append(1)
else:
series.append(series[-1] + series[-2])
for i in range(len(series)): # Convert the numbers to strings
series[i] = str(series[i])
return(', '.join(series)) # Return the sequence seperated by commas
def main(): # Wrapper function
print(fibSequence(int(input('How many numbers do you need? '))))
if __name__ == '__main__':
main()