forked from mouredev/retos-programacion-2023
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request mouredev#6008 from adra-dev/main
Reto mouredev#4 - Python
- Loading branch information
Showing
2 changed files
with
54 additions
and
0 deletions.
There are no files selected for viewing
46 changes: 46 additions & 0 deletions
46
Retos/Reto #4 - PRIMO, FIBONACCI Y PAR [Media]/python/adra-dev.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
""" | ||
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" | ||
""" | ||
import math | ||
|
||
|
||
def 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 | ||
|
||
|
||
|
||
prime_fibonacci_even(2) | ||
prime_fibonacci_even(7) | ||
prime_fibonacci_even(0) | ||
prime_fibonacci_even(13) | ||
prime_fibonacci_even(-2) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
""" | ||
Escribe un !Hola Mundo! en todos los lenguajes de programación que puedas. | ||
Seguro que hay algún lenguaje que te llama la atención y nunca has utilizado, | ||
o quizás quieres dar tus primeros pasos... ¡Pues este es el momento! | ||
A ver quién se atreve con uno de esos lenguajes que no solemos ver por ahí... | ||
""" | ||
|
||
print("Hola Mundo!") |