-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathFibonacciSquare.py
42 lines (28 loc) · 1.05 KB
/
FibonacciSquare.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
def main():
"""Main function."""
# Ask the user for an integer.
input_number = int(input("Input an integer: "))
# Decide whether the input number is a fibonacci sequence.
if check_fibonacci(0, 1, input_number) == input_number:
print("Fibonacci")
else:
print("Not a fibonacci")
# Decide whether the input number is a square.
if check_square(0, input_number) == input_number:
print("Square")
else:
print("Not a square")
def check_fibonacci(first, second, input_number):
"""Checks whether the input number is a fibonacci number."""
fibonacci_sum = first + second
if fibonacci_sum < input_number:
return check_fibonacci(second, fibonacci_sum, input_number)
return fibonacci_sum
def check_square(first, input_number):
"""Checks whether the input number is a perfect square."""
square = first * first
if square < input_number:
return check_square(first + 1, input_number)
return square
if __name__ == '__main__':
main()