Tuesday, July 28, 2020

Write a Program to Print the Fibonacci sequence in Python.

 Fibonacci sequence in Python.

The Fibonacci Sequence is the series of numbers: 0, 1, 1, 2, 3, 5, 8, 13, 21, 34, ... The next number is found by adding up the two numbers .

ms = int(input("Enter a Number :: "))

num1, num2 = 0, 1
count = 0

if ms <= 0:
   print("Please enter a positive integer")
elif ms == 1:
   print("Fibonacci sequence upto",ms,"::")
   print(num1)
else:
   print("Fibonacci sequence:")
   while count < ms:
       print(num1)
       n = num1 + num2
       num1 = num2
       num2 = n
       count += 1

OUTPUT

Enter a Number :: 7
Fibonacci sequence:
0
1
1
2
3
5
8

No comments:

Post a Comment

Please do not any spam link in Comment Box