Skip to content

Commit f992b92

Browse files
authored
Merge pull request #33 from Mownika25/patch-2
Create Fibbonacci.py
2 parents 42df33d + d52362d commit f992b92

File tree

1 file changed

+25
-0
lines changed

1 file changed

+25
-0
lines changed

Fibbonacci.py

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
# Program to display the Fibonacci sequence up to n-th term
2+
3+
nterms = int(input("How many terms? "))
4+
5+
# first two terms
6+
n1, n2 = 0, 1
7+
count = 0
8+
9+
# check if the number of terms is valid
10+
if nterms <= 0:
11+
print("Please enter a positive integer")
12+
# if there is only one term, return n1
13+
elif nterms == 1:
14+
print("Fibonacci sequence upto",nterms,":")
15+
print(n1)
16+
# generate fibonacci sequence
17+
else:
18+
print("Fibonacci sequence:")
19+
while count < nterms:
20+
print(n1)
21+
nth = n1 + n2
22+
# update values
23+
n1 = n2
24+
n2 = nth
25+
count += 1

0 commit comments

Comments
 (0)