Skip to content

Commit c3c09d4

Browse files
committed
#3 - Python
1 parent f243478 commit c3c09d4

File tree

1 file changed

+98
-0
lines changed

1 file changed

+98
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
# Estructuras #
2+
3+
# Listas (inserción, borrado, actualización y ordenación)
4+
list = ["Pedro", "Luis", "David"]
5+
print(list)
6+
list.append("Fernando")
7+
print(list)
8+
list.remove("Luis")
9+
print(list)
10+
print(list[1])
11+
list[1] = "Alejandra"
12+
print(list)
13+
list.sort()
14+
print(list)
15+
print(type(list))
16+
17+
# Tuplas (inmutables)
18+
tuple = ("Jessica", 76, "Ashley", 23.12, True)
19+
print(tuple)
20+
print(tuple[3])
21+
print(type(tuple))
22+
23+
# Sets (malas para buscar datos porque siempre estan desordenadas)
24+
set = {"Jessica", 76, "Ashley", 23.12, True}
25+
print(set)
26+
set.add(13)
27+
set.add(13) # Evita duplicados
28+
print(set)
29+
set.remove("Ashley")
30+
print(set)
31+
print(type(set))
32+
33+
# Diccionario (clave: valor)
34+
dictionary = {
35+
"name": "Josh",
36+
"username": "joshu725",
37+
"email": "[email protected]"
38+
}
39+
print(dictionary["username"])
40+
dictionary["age"] = 23
41+
print(dictionary)
42+
del dictionary["age"]
43+
print(dictionary)
44+
print(type(dictionary))
45+
46+
# Extra #
47+
48+
def agenda():
49+
50+
contacts = {}
51+
52+
def add_number(name, number):
53+
if number.isdigit() and len(number) == 10:
54+
contacts[name] = number
55+
else:
56+
print("Ingresa un número de 10 dígitos")
57+
58+
while True:
59+
print("==========================")
60+
print("1. Insertar")
61+
print("2. Actualizar")
62+
print("3. Eliminar")
63+
print("4. Buscar")
64+
print("\n5. Salir")
65+
print("==========================")
66+
option = input("> ")
67+
68+
match option:
69+
case "1":
70+
name = input("Introduce un nombre: ")
71+
number = input("Introduce el telefono: ")
72+
add_number(name, number)
73+
case "2":
74+
name = input("Introduce un nombre a actualizar: ")
75+
if name in contacts:
76+
number = input("Introduce el nuevo teléfono: ")
77+
add_number(name, number)
78+
else:
79+
print("No se ha encontrado el contacto")
80+
case "3":
81+
name = input("Introduce un nombre a eliminar: ")
82+
if name in contacts:
83+
del contacts[name]
84+
else:
85+
print("No se ha encontrado el contacto")
86+
case "4":
87+
name = input("Introduce un nombre a buscar: ")
88+
if name in contacts:
89+
print(f"El número de {name} es: {contacts[name]}")
90+
else:
91+
print("No se ha encontrado el contacto")
92+
case "5":
93+
print("Saliendo...")
94+
break
95+
case _:
96+
print("Opción inválida, ingresa un número del 1 al 5")
97+
98+
agenda()

0 commit comments

Comments
 (0)