[Python] To find if a number is fibonacci or not

Discussão em 'Python' iniciado por Stack, Agosto 30, 2025.

  1. Stack

    Stack Membro Participativo

    I am a student, new to python. I am trying to code a program that will tell if a user input number is fibonacci or not.

    num=int(input("Enter the number you want to check\n"))
    temp=1
    k=0
    a=0
    summ=0
    while summ<=num:
    summ=temp+k
    temp=summ
    k=temp
    if summ==num:
    a=a+1
    print("Yes. {} is a fibonnaci number".format(num))
    break
    if a==0:
    print("No. {} is NOT a fibonacci number".format(num))
    #The program is working for only numbers upto 2.

    Continue reading...

Compartilhe esta Página