From ae59e24a69ae95b210523a0f5d6f1c1b86d0ae8b Mon Sep 17 00:00:00 2001 From: Jai Gora Date: Thu, 1 Oct 2020 21:28:51 +0530 Subject: [PATCH] FibonacciSeries Program to print Fibonacci series in python --- FibonacciSeries.py | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100644 FibonacciSeries.py diff --git a/FibonacciSeries.py b/FibonacciSeries.py new file mode 100644 index 0000000..17e2422 --- /dev/null +++ b/FibonacciSeries.py @@ -0,0 +1,21 @@ +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