File tree Expand file tree Collapse file tree 1 file changed +77
-0
lines changed
Roadmap/07 - PILAS Y COLAS/python Expand file tree Collapse file tree 1 file changed +77
-0
lines changed Original file line number Diff line number Diff line change 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 ()
You can’t perform that action at this time.
0 commit comments