forked from mouredev/roadmap-retos-programacion
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSac-Corts.py
146 lines (112 loc) · 2.91 KB
/
Sac-Corts.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
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
"""
EJERCICIO
"""
# Clase Stack (Pila)
class Stack:
def __init__(self):
self.items = []
def push(self, item):
self.items.append(item)
def pop(self):
if not self.is_empty():
return self.items.pop()
else:
return None
def peek(self):
if not self.is_empty():
return self.items[-1]
else:
return None
def is_empty(self):
return len(self.items) == 0
def size(self):
return len(self.items)
pila = Stack()
pila.push(1)
pila.push(3)
pila.push(6)
print(pila.size()) # 3
print(pila.pop()) # 6
print(pila.peek()) # 3
print(pila.is_empty()) # False
# Clase Queue (Cola)
class Queue:
def __init__(self):
self.items = []
def enqueue(self, item):
self.items.append(item)
def dequeue(self):
if not self.is_empty():
return self.items.pop(0)
else:
return None
def peek(self):
if not self.is_empty():
return self.items[0]
else:
return None
def is_empty(self):
return len(self.items) == 0
def size(self):
return len(self.items)
fila = Queue()
fila.enqueue(1)
fila.enqueue(5)
fila.enqueue(10)
print(fila.size()) # 3
print(fila.dequeue()) # 1
print(fila.peek()) # 5
print(fila.is_empty()) # False
"""
DIFICULTAD EXTRA
"""
# Navegador Web
historial = []
adelante = []
def navegar_a(pagina):
historial.append(pagina)
adelante.clear()
def ir_atras():
if len(historial) > 1:
adelante.append(historial.pop())
print(f"Página actual: {historial[-1]} | {historial} | {adelante}")
else:
print("No hay más páginas atrás.")
def ir_adelante():
if adelante:
historial.append(adelante.pop())
print(f"Página actual: {historial[-1]} | {historial} | {adelante}")
else:
print("No hay más páginas adelante.")
while True:
comando = input("Introduce una página o 'atrás'/'adelante': ")
if comando == "atrás" or comando == "atras":
ir_atras()
elif comando == "adelante":
ir_adelante()
elif comando == "salir":
print("Saliendo del navegador...")
break
else:
navegar_a(comando)
print(f"Página actual: {comando} | {historial} | {adelante}")
# Impresora
documentos = []
def agregar_documento(documento):
documentos.append(documento)
def imprimir_documento():
if len(documentos) > 0:
imprimir = documentos.pop(0)
print(f"Imprimiendo {imprimir} | {documentos}")
else:
print("No hay impresiones por el momento")
while True:
comando = input("Introduce un documento o 'imprimir': ")
if comando == "imprimir":
imprimir_documento()
elif comando == "salir":
print("Apagando impresora...")
break
else:
agregar_documento(comando)
print("Fila de impresión:", documentos)