FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
pythonprogram/fibonacci.py at master · simranswaraj/pythonprogram · GitHub
simranswaraj
pythonprogram
Repository navigation
Code
Pull requests
Actions
Projects
Security and quality
Insights
Expand file tree
Breadcrumbs
pythonprogram
/
fibonacci.py
Copy path
More file actions
More file actions
Latest commit
History
History
History
23 lines (20 loc) · 496 Bytes
Breadcrumbs
pythonprogram
/
fibonacci.py
Copy path
File metadata and controls
23 lines (20 loc) · 496 Bytes
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
# Program to display the Fibonacci sequence up to n-th term
nterms
=
int
(
input
(
"How many terms? "
))
# first two terms
n1
,
n2
=
0
,
1
count
=
0
# check if the number of terms is valid
if
nterms
<=
0
:
print
(
"Please enter a positive integer"
)
elif
nterms
==
1
:
print
(
"Fibonacci sequence upto"
,
nterms
,
":"
)
print
(
n1
)
else
:
print
(
"Fibonacci sequence:"
)
while
count
<
nterms
:
print
(
n1
)
nth
=
n1
+
n2
# update values
n1
=
n2
n2
=
nth
count
+=
1
Back
|
FazBrowse Home
|
New Git URL