Skip to content

Commit 852428e

Browse files
authored
Merge pull request Aishanipach#29 from Skillz619/main
Added fibonacci_series.py
2 parents fab5a02 + 79f6388 commit 852428e

File tree

2 files changed

+31
-0
lines changed

2 files changed

+31
-0
lines changed

README.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,10 @@ Feel free to add basic python scripts/programs that helped you learn python. I h
3636
19. [Insertion Sort](https://github.com/musaibbatghar/Beginners-Python-Projects/blob/main/Insertion_Sort.py) - [Musaib Batghar](https://github.com/musaibbatghar)
3737
20. [Snake game](https://github.com/Aishanipach/Beginners-Python-Projects/compare/main...meanshkumar:Beginners-Python-Projects:main?expand=1)- [Ansh Kumar](https://github.com/meanshkumar)
3838
21. [Merge_Sort](https://github.com/proPrateekSahu/Beginners-Python-Projects/blob/main/MergeSort.py) - [Prateek Kumar Sahu](https://github.com/proPrateekSahu)
39+
40+
22. [Fibonacci_Series](https://github.com/Skillz619/Beginners-Python-Projects/blob/main/fibonacci_series.py) - [Shreekar Kolanu](https://github.com/Skillz619)
41+
3942
22. [Binary_Search](https://github.com/proPrateekSahu/Beginners-Python-Projects/blob/main/BinarySearch) - [Prateek Kumar Sahu](https://github.com/proPrateekSahu)
4043
23. [TowerOfHoni](https://github.com/proPrateekSahu/Beginners-Python-Projects/blob/main/towerOfHoni.py) - [Prateek Kumar Sahu](https://github.com/proPrateekSahu)
4144
24. [Matrix_Multiplier](https://github.com/proPrateekSahu/Beginners-Python-Projects/blob/main/MatrixMultiplier.py) - [Prateek Kumar Sahu](https://github.com/proPrateekSahu)
45+

fibonacci_series.py

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
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+
13+
# if there is only one term, return n1
14+
elif nterms == 1:
15+
print("Fibonacci sequence upto",nterms,":")
16+
print(n1)
17+
18+
# generate fibonacci sequence
19+
else:
20+
print("Fibonacci sequence:")
21+
while count < nterms:
22+
print(n1)
23+
nth = n1 + n2
24+
# update values
25+
n1 = n2
26+
n2 = nth
27+
count += 1

0 commit comments

Comments
 (0)