We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
2 parents 42df33d + d52362d commit f992b92Copy full SHA for f992b92
Fibbonacci.py
@@ -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
21
+ nth = n1 + n2
22
+ # update values
23
+ n1 = n2
24
+ n2 = nth
25
+ count += 1
0 commit comments