1
+ #Clases
2
+
3
+ class Programmer :
4
+
5
+ surname = None
6
+
7
+ def __init__ (self , name : str , age : int , languages : list ):
8
+ self .name = name
9
+ self .age = age
10
+ self .languajes = languages
11
+
12
+ def print (self ):
13
+ print (f"Nombre: { self .name } | Apellido: { self .surname } | Edad: { self .age } | Lenguajes { self .languajes } " )
14
+
15
+ my_programmer = Programmer ("Victor" , 21 , ["Python" , "Java" , "Swift" ])
16
+ my_programmer .print ()
17
+ my_programmer .surname = "Fer"
18
+ my_programmer .print ()
19
+ my_programmer .age = 22
20
+ my_programmer .print ()
21
+
22
+
23
+ #EJERCICIO EXTRA
24
+
25
+ #Pila
26
+ class Stack ():
27
+
28
+ def __init__ (self ):
29
+ self .stack = []
30
+
31
+ def agregarItem (self , item ):
32
+ self .stack .append (item )
33
+
34
+ def sacarItem (self ):
35
+ if self .numElem () == 0 :
36
+ return None
37
+ self .stack .pop ()
38
+
39
+ def numElem (self ):
40
+ return len (self .stack )
41
+
42
+ def print (self ):
43
+ if self .numElem () == 0 :
44
+ print ("Pila vacia" )
45
+ else :
46
+ for i in reversed (self .stack ):
47
+ print (i )
48
+
49
+
50
+ my_stack = Stack ()
51
+ my_stack .agregarItem ("A" )
52
+ my_stack .agregarItem ("B" )
53
+ my_stack .agregarItem ("C" )
54
+ my_stack .agregarItem ("D" )
55
+ print (my_stack .numElem ())
56
+ my_stack .print ()
57
+ my_stack .sacarItem ()
58
+ my_stack .sacarItem ()
59
+ my_stack .sacarItem ()
60
+ my_stack .sacarItem ()
61
+ my_stack .sacarItem ()
62
+ my_stack .sacarItem ()
63
+ print (my_stack .numElem ())
64
+ my_stack .print ()
65
+
66
+ #Cola
67
+
68
+ class Queue ():
69
+
70
+ def __init__ (self ):
71
+ self .queue = []
72
+
73
+ def agregarItem (self , item ):
74
+ self .queue .append (item )
75
+
76
+ def sacarItem (self ):
77
+ if self .numElem () == 0 :
78
+ return None
79
+ self .queue .pop ()
80
+
81
+ def numElem (self ):
82
+ return len (self .queue )
83
+
84
+ def print (self ):
85
+ if self .numElem () == 0 :
86
+ print ("Cola vacia" )
87
+ else :
88
+ for i in self .queue :
89
+ print (i )
90
+
91
+
92
+ my_queue = Queue ()
93
+ my_queue .agregarItem ("A" )
94
+ my_queue .agregarItem ("B" )
95
+ my_queue .agregarItem ("C" )
96
+ my_queue .agregarItem ("D" )
97
+ print (my_queue .numElem ())
98
+ my_queue .print ()
99
+ my_queue .sacarItem ()
100
+ my_queue .sacarItem ()
101
+ my_queue .sacarItem ()
102
+ my_queue .sacarItem ()
103
+ my_queue .sacarItem ()
104
+ my_queue .sacarItem ()
105
+ print (my_queue .numElem ())
106
+ my_queue .print ()
0 commit comments