I know how to make the list of the Fibonacci numbers, but i don't know how can i test if a given number belongs to the fibonacci list - one way that comes in mind is generate the list of fib. numbers up to that number and see if it belongs to the array, but there's got to be another, simpler and faster method.
Any ideas ?
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".
Step 1 : Declare one variable called inputNumber and store the user entered number in it. Step 2 : initialize firstTerm = 0, secondTerm = 1 and thirdTerm = 0 where firstTerm and secondTerm are the first two numbers of the series.
A very nice test is that N is a Fibonacci number if and only if 5 N^2 + 4
or 5N^2 – 4
is a square number. For ideas on how to efficiently test that a number is square refer to the SO discussion.
Hope this helps
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With