forked from mouredev/roadmap-retos-programacion
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMarcosE-FerretoE.py
93 lines (68 loc) · 1.78 KB
/
MarcosE-FerretoE.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
"""
Ejercicio
"""
# Pilas/Stack (LIFO)
stack = []
stack.append(1) # push
stack.append(2) # push
stack.append(3) # push
print(stack)
# pop
stack_item = stack[len(stack) - 1]
del stack[len(stack) - 1]
print(stack_item)
print(stack.pop())
print(stack)
# Cola/Queue (FIFO)
queue = []
queue.append(1) # enqueue
queue.append(2) # enqueue
queue.append(3) # enqueue
# dequeue
queue_item = queue[0]
del queue[0]
print(queue_item)
print(queue.pop(0))
print(queue)
"""
DIFICULTAD EXTRA
"""
def web_navigation():
stack = []
while True:
action = input("Añade una url o interactúa con palabras atrás/salir: ")
if action == "salir":
print("Saliendo del navegador web")
break
elif action == "atrás":
if len(stack) > 0:
print(stack.pop())
else:
print("No se pueden interactuar con palabras antes de añadir una ")
else:
stack.append(action)
if len(stack) > 0:
print(f"Has navegado a la web: {stack[len(stack) - 1]}")
else:
print("Estás en la página de inicio.")
# web_navigation()
def shared_printed():
queue = []
while True:
action = input("Añade un documento o selecciona imprimir/salir: ")
if action == "salir":
break
elif action == "imprimir":
if len(queue) > 0:
print(f"Imprimiendo: {queue.pop(0)}")
else:
print(
"No se pueden interactuar con palabras antes de añadir una impresión"
)
else:
queue.append(action)
if len(queue) > 0:
print(f"Cola de impresión: {queue}")
else:
print("Estás en la cola de inicio.")
shared_printed()