forked from mouredev/retos-programacion-2023
-
Notifications
You must be signed in to change notification settings - Fork 0
/
mouredev.py
39 lines (27 loc) · 880 Bytes
/
mouredev.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
import math
def check_prime_fibonacci_even(number):
result = f"{number} "
# Primo
if number > 1:
for index in range(2, number):
if number % index == 0:
result += "no es primo, "
break
else:
result += "es primo, "
else:
result += "no es primo, "
# Fibonacci
result += "es fibonacci " if number > 0 and (is_perfect_square(5 * number * number + 4) or is_perfect_square(
5 * number * number - 4)) else "no es fibonacci "
# Par
result += "y es par" if number % 2 == 0 else "y es impar"
print(result)
def is_perfect_square(number):
sqrt = int(math.sqrt(number))
return sqrt * sqrt == number
check_prime_fibonacci_even(2)
check_prime_fibonacci_even(7)
check_prime_fibonacci_even(0)
check_prime_fibonacci_even(1)
check_prime_fibonacci_even(-2)