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.
- Loading branch information
1 parent
97a2c78
commit 6e31b45
Showing
1 changed file
with
62 additions
and
0 deletions.
There are no files selected for viewing
62 changes: 62 additions & 0 deletions
62
Retos/Reto #44 - ADIVINANZAS MATEMÁTICAS [Media]/python/sirnas1983.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,62 @@ | ||
import random | ||
import time | ||
|
||
def operacion_aleatoria(tupla): | ||
a,b = tupla | ||
op = random.randint(1,4) | ||
if op == 1: | ||
res = a + b | ||
signo = '+' | ||
elif op == 2: | ||
res = a - b | ||
signo = '-' | ||
elif op == 3: | ||
res = a * b | ||
signo = 'x' | ||
else: | ||
if b == 0: | ||
b = 1 | ||
res = a // b | ||
signo = '//' | ||
return res, f"{a} {signo} {b} = " | ||
|
||
def operandos_aleatorios(nivel): | ||
a = random.randint(1,10**nivel) - 1 | ||
b = random.randint(1,10**nivel) - 1 | ||
return a, b | ||
|
||
def juego_matematicas(): | ||
jugar = input("¿Quieres jugar? s/n: ").lower() == "s" | ||
tiempo = 3 | ||
nivel = 1 | ||
correctas = 0 | ||
while jugar: | ||
if correctas == 0: | ||
print("¿Preparado?") | ||
print("Nota: En las divisiones ingresar la parte entera unicamente") | ||
time.sleep(0.7) | ||
resp, texto = operacion_aleatoria(operandos_aleatorios(nivel)) | ||
print(texto) | ||
cronom_on = time.time() | ||
guess = float(input("respuesta: ")) | ||
cronom_off = time.time() | ||
vuelta = cronom_off - cronom_on | ||
if vuelta > tiempo: | ||
print(f"Tiempo agotado, tienes {tiempo} seg. para contestar correctamente") | ||
jugar = False | ||
elif guess == resp: | ||
print("¡Respuesta correcta!") | ||
correctas += 1 | ||
if correctas % 5 == 0 and correctas < 16: | ||
nivel += 1 | ||
print(f"¡¡Felicidades, pasaste al nivel {nivel}!!") | ||
else: | ||
print("Respuesta incorrecta") | ||
print(f"La respuesta correcta era {resp}") | ||
jugar = False | ||
if not jugar: | ||
print("Gracias por participar") | ||
print(f"Usted logro {correctas} respuestas correctas") | ||
|
||
juego_matematicas() | ||
|