Run Code
|
API
|
Code Wall
|
Misc
|
Feedback
|
Login
|
Theme
|
Privacy
|
Patreon
2.1.19
""" Program to check if a number is a fibonacci number. Print number and if it is fibonacci number or not. Author: Jayesh Chandrapal """ import math def isfib(num): """ Checks if given number is a fibonacci number. @param num Number to be tested if it is fibonacci number @return Boolean value indicating if given number is a fibonacci number """ X1 = 5 * math.pow(num, 2) + 4 X2 = 5 * math.pow(num, 2) - 4 X1_sqrt = math.sqrt( X1 ) X2_sqrt = math.sqrt( X2 ) return (X1_sqrt * X1_sqrt == X1) or (X2_sqrt * X2_sqrt == X2) def test(): for i in range(1000, 10000): print("%d \t%s" % (i, "Yes" if isfib(i) else "No")) if __name__ == "__main__": test()
run
|
edit
|
history
|
help
0
shuru8
Code
pattern(T).py
calculate the sum of string 201test70de88qa ( only numbers)
Current date/time
Depth First Search - Find if path exists
abstractmethod
Get the longest repeated non-overlapping substring
total_tips
Hello world