Python program: Write a Python Program for printing Fibonacci numbers up to a given number

Python program: Write a Python Program for printing Fibonacci numbers up to a given number

max_num = 55
num = 0
prev_num = 0
curr_num = 0

while(num < 55):
    if(num == 0):
        print(num)
        num = num+1
        print(num)
        prev_num = 0      
    elif num == 1:
        num = num + prev_num
        print(num)
        prev_num = 1
        curr_num = num       
    else:
        num = prev_num + curr_num
        prev_num = curr_num
        curr_num = num
        print(num)
----------------------------------------------
Output:
0 1 1 2 3 5 8 13 21 34 55

Post a Comment

0 Comments