forked from mouredev/roadmap-retos-programacion
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathNightAlchemist.py
85 lines (63 loc) · 1.67 KB
/
NightAlchemist.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
#stacks
stack = ["a", "b", "c"]
stack.append("d")
stack.append("e")
stack.pop()
print(stack)
#queues
queue = ["a", "b", "c"]
queue.append("d")
queue.append("e")
queue.pop(0)
print(queue)
#deque
from collections import deque
queue = deque(["a", "b", "c"])
queue.append("d")
queue.append("e")
queue.popleft()
print(queue)
'''
Extra
'''
#Stack
def back_and_forth():
history = []
ahead = []
while True:
command = input("Enter a website, 'back' to go back, 'forward' to go forward, or 'exit' to quit: ")
if command == "exit":
break
elif command == "back":
if len(history) > 1:
ahead.append(history.pop())
print("Current:", history[-1])
else:
print("No more history to go back to.")
elif command == "forward":
if ahead:
history.append(ahead.pop())
print("Current:", history[-1])
else:
print("No forward history available.")
else:
history.append(command)
ahead.clear()
print("Current:", command)
back_and_forth()
#Queue
def printer():
print_queue = []
while True:
command = input("Enter a document name to add to the queue, 'print' to print, or 'exit' to quit: ")
if command == "exit":
break
elif command == "print":
if print_queue:
print("Printing:", print_queue.pop(0))
else:
print("The queue is empty. No documents to print.")
else:
print_queue.append(command)
print(f"'{command}' added to the queue.")
printer()