forked from mouredev/roadmap-retos-programacion
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathyoezequiel.py
123 lines (94 loc) · 3.02 KB
/
yoezequiel.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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
class Stack:
def __init__(self):
self.items = []
def is_empty(self):
return len(self.items) == 0
def push(self, item):
self.items.append(item)
def pop(self):
if not self.is_empty():
return self.items.pop()
else:
print("La pila está vacía")
def peek(self):
if not self.is_empty():
return self.items[-1]
else:
print("La pila está vacía")
def size(self):
return len(self.items)
class Queue:
def __init__(self):
self.items = []
def is_empty(self):
return len(self.items) == 0
def enqueue(self, item):
self.items.append(item)
def dequeue(self):
if not self.is_empty():
return self.items.pop(0)
else:
print("La cola está vacía")
def size(self):
return len(self.items)
def navegador():
historial = Stack()
actual = ""
while True:
comando = input("Ingrese 'adelante', 'atrás' o el nombre de una página web: ")
if comando == "adelante":
if not historial.is_empty():
actual = historial.pop()
print("Navegando adelante a:", actual)
else:
print("No hay más páginas hacia adelante")
elif comando == "atrás":
if actual != "":
historial.push(actual)
print("Navegando atrás desde:", actual)
actual = ""
else:
print("No hay más páginas hacia atrás")
else:
if actual != "":
historial.push(actual)
actual = comando
print("Navegando a:", actual)
navegador()
def navegador():
historial = Stack()
actual = ""
while True:
comando = input("Ingrese 'adelante', 'atrás' o el nombre de una página web: ")
if comando == "adelante":
if not historial.is_empty():
actual = historial.pop()
print("Navegando adelante a:", actual)
else:
print("No hay más páginas hacia adelante")
elif comando == "atrás":
if actual != "":
historial.push(actual)
print("Navegando atrás desde:", actual)
actual = ""
else:
print("No hay más páginas hacia atrás")
else:
if actual != "":
historial.push(actual)
actual = comando
print("Navegando a:", actual)
navegador()
def impresora():
documentos = Queue()
while True:
comando = input("Ingrese 'imprimir' o el nombre de un documento: ")
if comando == "imprimir":
if not documentos.is_empty():
print("Imprimiendo:", documentos.dequeue())
else:
print("No hay documentos en la cola para imprimir")
else:
documentos.enqueue(comando)
print("Documento agregado a la cola:", comando)
impresora()