File tree Expand file tree Collapse file tree 1 file changed +78
-0
lines changed
Roadmap/08 - CLASES/python Expand file tree Collapse file tree 1 file changed +78
-0
lines changed Original file line number Diff line number Diff line change 1+ #CLASES en PYHTON
2+
3+ class Developer :
4+ def __init__ (self , name : str , age : int ):
5+ self .name = name
6+ self .age = age
7+
8+ def saludar (self ):
9+ print (f"Hola soy el desarrollador { self .name } y tengo { self .age } años" )
10+
11+
12+ desarrollador_1 = Developer ("Juan" , 22 )
13+ desarrollador_1 .saludar ()
14+ desarrollador_1 .name = "Pablo"
15+ desarrollador_1 .age = 25
16+ desarrollador_1 .saludar ()
17+
18+
19+ #EJERCICIO EXTRA
20+
21+
22+ class Pila :
23+
24+ def __init__ (self ):
25+ self .stack = []
26+
27+ def apilar (self , item ):
28+ self .stack .append (item )
29+
30+ def desapilar (self ):
31+ if self .contador () == 0 :
32+ return None
33+ return self .stack .pop ()
34+
35+ def contador (self ):
36+ return len (self .stack )
37+
38+ def listar (self ):
39+ for i in reversed (self .stack ):
40+ print (i )
41+
42+ # mi_pila = Pila()
43+ # mi_pila.apilar("ITEM1")
44+ # mi_pila.apilar("ITEM2")
45+ # mi_pila.apilar("ITEM3")
46+ # mi_pila.contador()
47+ # mi_pila.listar()
48+ # mi_pila.desapilar()
49+ # print("-------------------")
50+ # mi_pila.contador()
51+ # mi_pila.listar()
52+
53+ class Cola :
54+ def __init__ (self ):
55+ self .line = []
56+
57+ def encolar (self , item ):
58+ self .line .append (item )
59+
60+ def desencolar (self ):
61+ if self .contador () == 0 :
62+ return None
63+ return self .line .pop (0 )
64+
65+ def contador (self ):
66+ return len (self .line )
67+
68+ def listar (self ):
69+ for i in (self .line ):
70+ print (i )
71+
72+ cola_1 = Cola ()
73+ cola_1 .encolar ("ITEM1" )
74+ cola_1 .encolar ("ITEM2" )
75+ cola_1 .encolar ("ITEM3" )
76+ print (cola_1 .contador ())
77+ cola_1 .listar ()
78+ cola_1 .desencolar ()
You can’t perform that action at this time.
0 commit comments