-
Notifications
You must be signed in to change notification settings - Fork 0
/
Prueba.py
85 lines (73 loc) · 3.14 KB
/
Prueba.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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
import random
import os
# Soy Jefferson Mejia
# Colores para la salida
class Colores:
HEADER = '\033[95m'
OKBLUE = '\033[94m'
OKCYAN = '\033[96m'
OKGREEN = '\033[92m'
WARNING = '\033[93m'
FAIL = '\033[91m'
ENDC = '\033[0m'
BOLD = '\033[1m'
UNDERLINE = '\033[4m'
def limpiar_pantalla():
os.system('cls' if os.name == 'nt' else 'clear')
def jugar_adivina_el_numero():
limpiar_pantalla()
print(f"{Colores.HEADER}{Colores.BOLD}¡Bienvenido al juego de Adivina el Número!{Colores.ENDC}")
nombre = input("¿Cuál es tu nombre? ")
mejores_puntajes = {}
while True:
limpiar_pantalla()
print(f"{Colores.OKCYAN}Hola, {nombre}. Elige un nivel de dificultad:{Colores.ENDC}")
print("1. Fácil (1-50)")
print("2. Medio (1-100)")
print("3. Difícil (1-200)")
while True:
try:
nivel = int(input("Introduce el nivel (1-3): "))
if nivel in [1, 2, 3]:
break
else:
print(f"{Colores.WARNING}Por favor, introduce un número válido (1-3).{Colores.ENDC}")
except ValueError:
print(f"{Colores.FAIL}Entrada no válida. Por favor, introduce un número entero.{Colores.ENDC}")
if nivel == 1:
rango = 50
elif nivel == 2:
rango = 100
else:
rango = 200
numero_secreto = random.randint(1, rango)
intentos = 0
print(f"{Colores.OKCYAN}Estoy pensando en un número entre 1 y {rango}.{Colores.ENDC}")
while True:
try:
intento = int(input("Introduce tu intento: "))
intentos += 1
if intento < 1 or intento > rango:
print(f"{Colores.WARNING}Por favor, introduce un número entre 1 y {rango}.{Colores.ENDC}")
continue
if intento < numero_secreto:
print(f"{Colores.WARNING}Demasiado bajo. Intenta de nuevo.{Colores.ENDC}")
elif intento > numero_secreto:
print(f"{Colores.WARNING}Demasiado alto. Intenta de nuevo.{Colores.ENDC}")
else:
print(f"{Colores.OKGREEN}¡Felicidades, {nombre}! Has adivinado el número en {intentos} intentos.{Colores.ENDC}")
if nombre in mejores_puntajes:
if intentos < mejores_puntajes[nombre]:
mejores_puntajes[nombre] = intentos
else:
mejores_puntajes[nombre] = intentos
break
except ValueError:
print(f"{Colores.FAIL}Entrada no válida. Por favor, introduce un número entero.{Colores.ENDC}")
print(f"{Colores.OKBLUE}Tu mejor puntaje: {mejores_puntajes[nombre]} intentos.{Colores.ENDC}")
jugar_de_nuevo = input("¿Quieres jugar de nuevo? (s/n): ")
if jugar_de_nuevo.lower() != 's':
print(f"{Colores.HEADER}{Colores.BOLD}¡Gracias por jugar, {nombre}! Hasta la próxima.{Colores.ENDC}")
break
if __name__ == "__main__":
jugar_adivina_el_numero()