forked from mouredev/roadmap-retos-programacion
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathidiegorojas.py
34 lines (31 loc) · 1.18 KB
/
idiegorojas.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
# Simulación de navegador web con pilas
def navegador_web():
historial_atras = []
historial_adelante = []
pagina_actual = None
while True:
accion = input("Ingresa una página web, 'atrás', 'adelante' o 'salir': ").strip().lower()
if accion == "salir":
print("Saliendo del navegador...")
break
elif accion == "atrás":
if historial_atras:
historial_adelante.append(pagina_actual)
pagina_actual = historial_atras.pop()
print(f"Yendo atrás a: {pagina_actual}")
else:
print("No hay páginas anteriores.")
elif accion == "adelante":
if historial_adelante:
historial_atras.append(pagina_actual)
pagina_actual = historial_adelante.pop()
print(f"Yendo adelante a: {pagina_actual}")
else:
print("No hay páginas siguientes.")
else:
if pagina_actual:
historial_atras.append(pagina_actual)
pagina_actual = accion
historial_adelante.clear()
print(f"Navegando a: {pagina_actual}")
navegador_web()