Skip to content

Commit 53fead4

Browse files
authored
Merge pull request mouredev#4571 from carrenoalexander/main
#3 - Python
2 parents b4a6252 + 7029d63 commit 53fead4

File tree

1 file changed

+129
-0
lines changed

1 file changed

+129
-0
lines changed
Lines changed: 129 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,129 @@
1+
"""
2+
* Estruturas de datos
3+
"""
4+
5+
# Lista
6+
7+
my_list = [1, 1, 2, 3, 5, 6]
8+
print(my_list)
9+
print(type(my_list))
10+
11+
my_list.insert(4, 4) # Inserción
12+
print(my_list)
13+
14+
my_list.remove(6) # Borrado
15+
print(my_list)
16+
17+
my_list[0] = 0 # Actualización
18+
print(my_list)
19+
20+
my_list.sort(reverse=True) # Ordenación descendente
21+
print(my_list)
22+
23+
# Tupla
24+
25+
my_tuple = (1, 2, 3, 4, 5)
26+
print(my_tuple)
27+
print(type(my_tuple))
28+
29+
# Set
30+
31+
my_set = {1, 2, 3, 4, 5}
32+
print(my_set)
33+
print(type(my_set))
34+
35+
my_set.add(6) # Inserción
36+
print(my_set)
37+
38+
my_set.remove(6) # Borrado
39+
print(my_set)
40+
41+
# Diccionario
42+
43+
my_dict = {
44+
"Month": "July",
45+
"Day": "Tuesday",
46+
"Year": 2024
47+
}
48+
print(my_dict)
49+
print(type(my_dict))
50+
51+
my_dict["Century"] = "XXI" # Inserción
52+
print(my_dict)
53+
54+
del my_dict["Century"] # Borrado
55+
print(my_dict)
56+
57+
my_dict["Month"] = "June" # Actualización
58+
print(my_dict)
59+
60+
my_dict = dict(sorted(my_dict.items())) # Ordenación
61+
print(my_dict)
62+
63+
"""
64+
* Extra
65+
"""
66+
67+
def menu():
68+
print("=====================================")
69+
print("WELCOME TO THE CONTACTS AGENDA")
70+
print("1. Search contact")
71+
print("2. Insert contact")
72+
print("3. Update contact")
73+
print("4. Delete contact")
74+
print("5. Exit")
75+
print("=====================================")
76+
77+
menu()
78+
79+
80+
def contacts_agenda():
81+
82+
agenda = {}
83+
84+
def validate_phone_number(phone):
85+
return phone.isdigit() and len(phone) == 11
86+
87+
while True:
88+
option = input("Choose an option: ")
89+
90+
match option:
91+
case "1":
92+
name = input("Enter the name to search: ")
93+
if name in agenda:
94+
print(f"The phone number of {name} is {agenda[name]}")
95+
else:
96+
print("Contact not found")
97+
case "2":
98+
name = input("Enter the name to insert: ")
99+
phone = input("Enter the phone: ")
100+
if validate_phone_number(phone):
101+
agenda[name] = phone
102+
print("Contact inserted")
103+
else:
104+
print("Invalid phone number")
105+
case "3":
106+
name = input("Enter the name to update the phone: ")
107+
if name in agenda:
108+
phone = input("Enter the new phone: ")
109+
if validate_phone_number(phone):
110+
agenda[name] = phone
111+
print("Contact updated")
112+
else:
113+
print("Invalid phone number")
114+
else:
115+
print("Contact not found")
116+
case "4":
117+
name = input("Enter the name to delete: ")
118+
if name in agenda:
119+
del agenda[name]
120+
print("Contact deleted")
121+
else:
122+
print("Contact not found")
123+
case "5":
124+
print("Exiting...")
125+
break
126+
case _:
127+
print("Invalid option... Retry")
128+
129+
contacts_agenda()

0 commit comments

Comments
 (0)