diff --git a/Python/Fibonacci_Series.py b/Python/Fibonacci_Series.py new file mode 100644 index 0000000..1c15a0b --- /dev/null +++ b/Python/Fibonacci_Series.py @@ -0,0 +1,29 @@ +# Program to display the Fibonacci sequence up to given term + +# take n terms from user +n = int(input("How many terms? ")) + +# first two terms +n1, n2 = 0, 1 +count = 0 + +# check if the number of terms is valid +if n <= 0: + print("Please enter a positive integer") + +# if there is only one term, return n1 +elif n == 1: + print("Fibonacci sequence upto", n, ":") + print(n1) + +# generate fibonacci sequence +else: + print("Fibonacci sequence for ", n, " terms") + while count < n: + print(n1) + nth = n1 + n2 + + # update values + n1 = n2 + n2 = nth + count += 1