Skip to content

Commit a18286b

Browse files
Merge pull request seeditsolution#291 from DhanrajDesai/patch-1
Fibonacci number
2 parents aca5270 + ea9b6a9 commit a18286b

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

Fibonacci number

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
2+
import math
3+
def isPerfectSquare(x):
4+
s = int(math.sqrt(x))
5+
return s*s == x
6+
7+
8+
def isFibonacci(n):
9+
10+
return isPerfectSquare(5*n*n + 4) or isPerfectSquare(5*n*n - 4)
11+
12+
13+
for i in range(1,11):
14+
if (isFibonacci(i) == True):
15+
print i,"is a Fibonacci Number"
16+
else:
17+
print i,"is a not Fibonacci Number "

0 commit comments

Comments
 (0)