Skip to content

Commit 2ce9bde

Browse files
ayushmishra6198tstreamDOTh
authored andcommitted
Fibonacci Series in python (#346)
* Fibonacci Series in python * fibonacci series in python * fibonacci series in python
1 parent 1e1d47e commit 2ce9bde

File tree

3 files changed

+84
-0
lines changed

3 files changed

+84
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
# Program to display the Fibonacci sequence up to n-th term where n is provided by the user
2+
3+
# change this value for a different result
4+
nterms = int (input("enter the no. of terms " ))
5+
6+
# uncomment to take input from the user
7+
#nterms = int(input("How many terms? "))
8+
9+
# first two terms
10+
n1 = 0
11+
n2 = 1
12+
count = 0
13+
14+
# check if the number of terms is valid
15+
if nterms <= 0:
16+
print("Please enter a positive integer")
17+
elif nterms == 1:
18+
print("Fibonacci sequence upto",nterms,":")
19+
print(n1)
20+
else:
21+
print("Fibonacci sequence upto",nterms,":")
22+
while count < nterms:
23+
print(n1,end=' , ')
24+
nth = n1 + n2
25+
# update values
26+
n1 = n2
27+
n2 = nth
28+
count += 1

Fibonacci_series.py

+28
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
# Program to display the Fibonacci sequence up to n-th term where n is provided by the user
2+
3+
# change this value for a different result
4+
nterms = int (input("enter the no. of terms " ))
5+
6+
# uncomment to take input from the user
7+
#nterms = int(input("How many terms? "))
8+
9+
# first two terms
10+
n1 = 0
11+
n2 = 1
12+
count = 0
13+
14+
# check if the number of terms is valid
15+
if nterms <= 0:
16+
print("Please enter a positive integer")
17+
elif nterms == 1:
18+
print("Fibonacci sequence upto",nterms,":")
19+
print(n1)
20+
else:
21+
print("Fibonacci sequence upto",nterms,":")
22+
while count < nterms:
23+
print(n1,end=' , ')
24+
nth = n1 + n2
25+
# update values
26+
n1 = n2
27+
n2 = nth
28+
count += 1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
# Program to display the Fibonacci sequence up to n-th term where n is provided by the user
2+
3+
# change this value for a different result
4+
nterms = int (input("enter the no. of terms " ))
5+
6+
# uncomment to take input from the user
7+
#nterms = int(input("How many terms? "))
8+
9+
# first two terms
10+
n1 = 0
11+
n2 = 1
12+
count = 0
13+
14+
# check if the number of terms is valid
15+
if nterms <= 0:
16+
print("Please enter a positive integer")
17+
elif nterms == 1:
18+
print("Fibonacci sequence upto",nterms,":")
19+
print(n1)
20+
else:
21+
print("Fibonacci sequence upto",nterms,":")
22+
while count < nterms:
23+
print(n1,end=' , ')
24+
nth = n1 + n2
25+
# update values
26+
n1 = n2
27+
n2 = nth
28+
count += 1

0 commit comments

Comments
 (0)