Skip to content

Commit 629450d

Browse files
authored
Merge pull request #8935 from Irenetitor/pr/07-Python
07-Python
2 parents 3578ce7 + d6b8d00 commit 629450d

File tree

1 file changed

+77
-0
lines changed

1 file changed

+77
-0
lines changed
Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
#Stacks - LIFO (Last In First Out)
2+
stack = []
3+
4+
stack.append(1)
5+
stack.append(2)
6+
stack.append(3)
7+
stack.append(4)
8+
9+
print(stack)
10+
11+
print(stack.pop())
12+
print(stack.pop())
13+
print(stack)
14+
15+
#Queue - FIFO (First In First Out)
16+
queue = []
17+
18+
queue.append(6)
19+
queue.append(7)
20+
queue.append(8)
21+
queue.append(9)
22+
23+
print(queue)
24+
25+
print(queue.pop(0))
26+
print(queue.pop(0))
27+
28+
print(queue)
29+
30+
#Extra exercises
31+
#First
32+
33+
def browsing_web():
34+
35+
moves = []
36+
37+
while True:
38+
action = input("Add a URL or interact using the following words: forward, back, exit.")
39+
40+
if action == "forward":
41+
pass
42+
elif action == "back":
43+
if len(moves) > 0:
44+
moves.pop()
45+
elif action == "exit":
46+
print(f"Leaving the website")
47+
break
48+
else:
49+
moves.append(action)
50+
51+
if len(action) > 0:
52+
print(f"You have navigated to: {moves[len(moves) - 1]}")
53+
else:
54+
print("You are on the home page.")
55+
56+
browsing_web()
57+
58+
#Second
59+
60+
def print_doc():
61+
62+
Docs = []
63+
64+
while True:
65+
66+
action = input("Add a document or select print/exit: ")
67+
68+
if action == "exit":
69+
break
70+
elif action == "print":
71+
print(f"Printing: {Docs(0)}")
72+
else:
73+
Docs.append(action)
74+
75+
print(f"Print queue: {Docs}")
76+
77+
print_doc()

0 commit comments

Comments
 (0)