forked from mouredev/roadmap-retos-programacion
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathycanas.py
141 lines (92 loc) · 2.41 KB
/
ycanas.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
import time
# ------ Ejercicio
# 1. Pilas
class Stack:
# Stack Data Structure
def __init__(self):
self.stack = []
def isempty(self):
return self.stack == []
def push(self, item):
self.stack.append(item)
def pop(self):
return self.stack.pop()
def top(self):
return self.stack[-1]
def size(self):
return len(self.stack)
my_stack = Stack()
print("Empty ?", my_stack.isempty())
my_stack.push('A')
my_stack.push('B')
my_stack.push('C')
print("Top:", my_stack.top())
print("Pop:", my_stack.pop())
print("Top:", my_stack.top())
print("Size:", my_stack.size())
print()
# 2. Colas
class Queue:
# Queue Data Structure
def __init__(self):
self.queue = []
def isempty(self):
return self.queue == []
def push(self, item):
self.queue.append(item)
def pop(self):
return self.queue.pop(0)
def top(self):
return self.queue[0]
def size(self):
return len(self.queue)
my_queue = Queue()
print("Empty ?", my_queue.isempty())
my_queue.push('A')
my_queue.push('B')
my_queue.push('C')
print("Top:", my_queue.top())
print("Pop:", my_queue.pop())
print("Top:", my_queue.top())
print("Size:", my_queue.size())
print()
# ------ Extra
# 1. Navegador
def webpage():
stack = ["htts://ycanas.com"]
while True:
print()
action = input(f"Ingrese el subdominio de la url al que quiere ingresar [{stack[0]}] o (atras/salír): ")
action = action.lower()
if action == "adelante":
pass
elif action == "atras":
if len(stack) > 1:
stack.pop()
elif action == "salir":
print("* Saliendo del navegador...")
break
else:
stack.append(action)
print("*", "/".join(stack))
webpage()
print()
# 2. Impresora
def printer():
queue = []
while True:
print()
action = input("Cargue un documento o (imprimir/salír): ")
action = action.lower()
if action == "salir":
print("* Apagando impresora...")
break
elif action == "imprimir":
if not queue == []:
print(f"* Imprimiendo {queue.pop(0)}")
time.sleep(1.5)
print("* Impresión terminada...")
else:
queue.append(action)
printer()
print()