Skip to content

Commit 7f7233c

Browse files
satishjasthit2013anurag
authored andcommitted
Add a program to print fibonacci series in python
1 parent f96120d commit 7f7233c

File tree

1 file changed

+41
-0
lines changed

1 file changed

+41
-0
lines changed

fibonacci/fibonacci.py

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
#!/usr/bin/python
2+
"""
3+
Script to generate fibonacci series in python_2.7
4+
"""
5+
6+
def fibonacci_series():
7+
"""
8+
arguments:
9+
----------
10+
none
11+
12+
returns:
13+
--------
14+
v: series of int
15+
16+
description:
17+
------------
18+
function to return fibonacci series from 1 to n terms
19+
"""
20+
#first and second terms
21+
n1 = 0
22+
n2 = 1
23+
24+
#getting number of terms
25+
n = int(raw_input("Enter the number of terms: "))
26+
print "Fibonacci Series: ",
27+
28+
if n == 0:
29+
print n1
30+
elif n == 1:
31+
print n1,", ",n2
32+
else:
33+
print n1,", ",n2,", ",
34+
for i in range(1,n):
35+
print n2+n1,", ",
36+
n3 = n2+n1
37+
n1 = n2
38+
n2 = n3
39+
40+
if __name__ == "__main__":
41+
fibonacci_series()

0 commit comments

Comments
 (0)