Python Program to Print the Fibonacci sequence

Updated: May 18, 2020


Python Program to Print the Fibonacci sequence Using While Loop


num = int(input("How many terms? ")) a, b = 0, 1 i = 0 if num <= 0: print("Please enter a positive integer") elif num == 1: print("Fibonacci sequence upto",num,":") print(a) else: print("Fibonacci sequence:") while i < num: print(a) c = a + b a = b b = c i += 1


Output:

How many terms? 4 Fibonacci sequence: 0 1 1 2


27 views0 comments

Recent Posts

See All
 

9555593818

Thakurdwara, Uttar Pradesh 244601, India

  • Facebook
  • Twitter
  • LinkedIn