Skip to content

Commit

Permalink
Merge pull request #6423 from restevean/develop
Browse files Browse the repository at this point in the history
#4 - Python
  • Loading branch information
Roswell468 authored Mar 21, 2024
2 parents 0b6c653 + da9f341 commit 0db934f
Showing 1 changed file with 43 additions and 0 deletions.
43 changes: 43 additions & 0 deletions Retos/Reto #4 - PRIMO, FIBONACCI Y PAR [Media]/python/restevean.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
"""
Escribe un programa que, dado un número, compruebe y muestre si es primo, fibonacci y par.
Ejemplos:
- Con el número 2, nos dirá: "2 es primo, fibonacci y es par"
- Con el número 7, nos dirá: "7 es primo, no es fibonacci y es impar"
"""


def is_prime(n):
if n < 2:
return False
for i in range(2, n):
if n % i == 0:
return False
return True


def is_fibonacci(n):
x, y = 0, 1
while y < n:
x, y = y, x + y
return y == n


def is_even(n):
return n % 2 == 0


def check_number(n):
primo = "is prime" if is_prime(n) else "it is not prime"
fibonacci = "is fibonacci" if is_fibonacci(n) else "it is not fibonacci"
par = "is even" if is_even(n) else "it is not even"
return f"{n} {primo}, {fibonacci} y {par}"


print(check_number(0))
print(check_number(2))
print(check_number(1))
print(check_number(3))
print(check_number(4))
print(check_number(5))
print(check_number(6))
print(check_number(7))

0 comments on commit 0db934f

Please sign in to comment.