Skip to content

Commit 0a7d828

Browse files
authored
Merge pull request mouredev#4693 from Gordo-Master/#3-Python
#3 - Python
2 parents 057c006 + 3e43b87 commit 0a7d828

File tree

1 file changed

+154
-0
lines changed

1 file changed

+154
-0
lines changed
Lines changed: 154 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,154 @@
1+
"""
2+
Estrutura de datos
3+
"""
4+
5+
# Listas
6+
my_list = [] # Constructor
7+
my_other_list = list() # Constructor
8+
my_list.append("manzana") # Inserción
9+
my_list.extend(["pera","uva"]) # Inserción
10+
print(my_list)
11+
del my_list[1] # Borrado
12+
print(my_list)
13+
my_list.remove("uva") # Borrado
14+
print(my_list)
15+
my_list[0] = "lechuga" # Actualización
16+
print(my_list)
17+
my_list.extend(["tomate","queso","mortadela","mayonesa"])
18+
print(my_list)
19+
my_list.sort() # Ordenación
20+
print(my_list)
21+
22+
# Tuplas
23+
my_tuple = () # Constructor
24+
my_other_tuple = tuple() # Constructor
25+
my_thrith_tuple = 10, 2, 1 # Constructor
26+
my_fourth_tuple = ("Lunes", "Miercoles", "Viernes") # Constructor
27+
print(type(my_thrith_tuple))
28+
print(my_thrith_tuple[2]) # Acceso
29+
my_thrith_tuple = tuple(sorted(my_thrith_tuple)) # Ordenación
30+
print(my_thrith_tuple)
31+
print(type(my_thrith_tuple))
32+
33+
# Conjuntos/Sets
34+
my_set = set() # Constructor
35+
my_other_set = {1,"Ottawa","Roma"} # Constructor
36+
print(my_other_set)
37+
my_other_set.add("Madrid") # Inserción
38+
print(my_other_set)
39+
my_other_set.remove(1) # Borrado
40+
print(my_other_set)
41+
my_other_set = set(sorted(my_other_set)) # No se puede ordenar por definición
42+
print(my_other_set)
43+
print(type(my_other_set))
44+
45+
# Diccionarios
46+
my_dict = dict()
47+
my_other_dict = {}
48+
my_thrith_dict = {
49+
"english":"hello world!",
50+
"español":"¡Hola mundo!"
51+
}
52+
print(my_thrith_dict)
53+
my_thrith_dict["Deutsch"] = "Hallo Welt" # Inserción
54+
print(my_thrith_dict)
55+
my_thrith_dict["Deutsch"] = "Hallo Welt!" # Actualización
56+
print(my_thrith_dict)
57+
del my_thrith_dict["Deutsch"] # Actualización
58+
print(my_thrith_dict)
59+
my_thrith_dict = dict(sorted(my_thrith_dict.items())) # Ordenación
60+
print(my_thrith_dict)
61+
print(type(my_thrith_dict))
62+
63+
64+
"""
65+
Ejercicio Extra
66+
"""
67+
68+
contact_list = {}
69+
70+
def find_contact(name: str, contact_list: dict) -> list:
71+
if name in contact_list:
72+
print(f"El numero de telefono de {name} es {contact_list[name]}")
73+
else:
74+
print(f"No existe el contacto {name}")
75+
return contact_list
76+
77+
def insert_contact(name: str, contact_list: dict):
78+
if name not in contact_list:
79+
number = input("Ingrese el número: ")
80+
if number.isdigit() and len(number) > 0 and len(number) < 11:
81+
contact_list[name] = number
82+
print(f"Contacto: {name}: {number} agregado")
83+
else:
84+
print("Numero invalido. \nDebes introducir un numero de telefono con un maximo de 11 dígitos")
85+
else:
86+
print("El contacto ya existe")
87+
return contact_list
88+
89+
90+
def refresh_contact(name: str, contact_list: dict):
91+
if name in contact_list:
92+
number = input("Ingrese el nuevo número: ")
93+
if number.isdigit() and len(number) > 0 and len(number) < 11:
94+
contact_list[name] = number
95+
print(f"Contacto: {name}: {number} actualizado")
96+
else:
97+
print("Numero invalido. \nDebes introducir un numero de telefono con un maximo de 11 dígitos")
98+
else:
99+
print("El contacto no existe")
100+
return contact_list
101+
102+
def del_contact(name: str, contact_list: dict):
103+
if name in contact_list:
104+
del contact_list[name]
105+
print(f"Contacto: {name} eliminado")
106+
else:
107+
print("El contacto no existe")
108+
return contact_list
109+
110+
def show_menu():
111+
print("*"*20)
112+
print("AGENDA DE CONTACTOS.")
113+
print("Operaciones:")
114+
print("1. Buscar contacto.")
115+
print("2. Insertar contacto.")
116+
print("3. Actualizar contacto")
117+
print("4. Borrar contacto")
118+
print("5. Salir")
119+
120+
def my_agenda(action=0):
121+
contact_list = {}
122+
123+
while True:
124+
show_menu()
125+
action = input("Opción: ")
126+
match action:
127+
case "1":
128+
contact_list = find_contact(
129+
input("Ingrese el nombre del contacto: "),
130+
contact_list=contact_list
131+
)
132+
case "2":
133+
contact_list = insert_contact(
134+
input("Ingrese el nombre del contacto: "),
135+
contact_list=contact_list
136+
)
137+
case "3":
138+
contact_list = refresh_contact(
139+
input("Ingrese el nombre del contacto: "),
140+
contact_list=contact_list
141+
)
142+
case "4":
143+
contact_list = del_contact(
144+
input("Ingrese el nombre del contacto: "),
145+
contact_list=contact_list
146+
)
147+
case "5":
148+
print("Saliendo...")
149+
break
150+
case _:
151+
print("Valor invalido, ingrese una opción del 1 al 5")
152+
input("\n\nPulse enter para continuar")
153+
154+
my_agenda()

0 commit comments

Comments
 (0)