-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathU1-Ejercicio-2.py
More file actions
33 lines (25 loc) · 872 Bytes
/
U1-Ejercicio-2.py
File metadata and controls
33 lines (25 loc) · 872 Bytes
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
"""
Genera un número aleatorio entre 1 y 100. El usuario debe adivinarlo.
El programa debe dar pistas "mayor" o "menor" hasta que acierte.
Muestra cuántos intentos necesitó.
"""
import random
def adivina_numero():
numero_secreto = random.randint(1, 100)
intentos = 0
print("🎯 Adivina el número entre 1 y 100")
while True:
try:
intento = int(input("Tu intento: "))
intentos += 1
if intento < numero_secreto:
print("⬆️ Mayor...")
elif intento > numero_secreto:
print("⬇️ Menor...")
else:
print(f"🎉 ¡Correcto! Adivinaste en {intentos} intentos")
break
except ValueError:
print("Por favor ingresa un número válido")
# Ejecutar
adivina_numero()