Skip to content

Commit 4058348

Browse files
authored
Merge pull request mouredev#3738 from luisssSoto/03-Python
#3 - Python
2 parents b3fdbd8 + 873e81b commit 4058348

File tree

1 file changed

+131
-0
lines changed

1 file changed

+131
-0
lines changed
Lines changed: 131 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,131 @@
1+
# /*
2+
# * EJERCICIO:
3+
# * - Muestra ejemplos de creación de todas las estructuras soportadas por defecto en tu lenguaje.
4+
# * - Utiliza operaciones de inserción, borrado, actualización y ordenación.
5+
# *
6+
# * DIFICULTAD EXTRA (opcional):
7+
# * Crea una agenda de contactos por terminal.
8+
# * - Debes implementar funcionalidades de búsqueda, inserción, actualización y eliminación de contactos.
9+
# * - Cada contacto debe tener un nombre y un número de teléfono.
10+
# * - El programa solicita en primer lugar cuál es la operación que se quiere realizar, y a continuación
11+
# * los datos necesarios para llevarla a cabo.
12+
# * - El programa no puede dejar introducir números de teléfono no númericos y con más de 11 dígitos.
13+
# * (o el número de dígitos que quieras)
14+
# * - También se debe proponer una operación de finalización del programa.
15+
# */
16+
17+
"""Lists, Tuples, Dictionaries and Sets"""
18+
'''Lists are mutable'''
19+
zoo=['rhino', 'elephant']
20+
print(zoo)
21+
22+
#looking forward
23+
myfavoriteAnimal = zoo[0]
24+
print(myfavoriteAnimal)
25+
26+
#insert an element
27+
zoo.append('owl')
28+
print(zoo)
29+
30+
#delete last element
31+
anotherZoo = zoo.pop()
32+
print(anotherZoo)
33+
34+
#remove one element
35+
zoo.remove('rhino')
36+
print(zoo)
37+
38+
#update
39+
zoo.insert(1, 'lion')
40+
41+
#order a list
42+
zoo.sort()
43+
print(zoo)
44+
print()
45+
46+
'''tuples'''
47+
#they are immutable, so that there are lots of limitations
48+
t = (1,2,2,4,6,1,3)
49+
print(t)
50+
51+
print(1 in t)
52+
print(2 not in t)
53+
54+
'''Dictionaries'''
55+
d = {'dog': 'perro', 'cat': 'gato'}
56+
57+
'''iterate and indexar for the dictionaries'''
58+
for americanAnimal in d:
59+
print(americanAnimal, end=' ')
60+
print()
61+
62+
for spanishAnimal in d:
63+
print(d[spanishAnimal], end=' ')
64+
print()
65+
66+
'''Set'''
67+
#It couldn't exist more than 1 element in the set
68+
s = {1,2,2,9}
69+
print(s)
70+
print()
71+
72+
'''Exercise'''
73+
telephoneDiary = {'Luis': 3310147389}
74+
conditional = True
75+
welcome = '''Tell me what would you do first:
76+
type...
77+
1 to add a contact
78+
2 to search a contact
79+
3 to update a contact
80+
4 to delete a contact
81+
5 to exit the program: '''
82+
def lookingContact(name):
83+
try:
84+
return telephoneDiary[name]
85+
except LookupError as e:
86+
print('The name was not found', e)
87+
88+
while conditional == True:
89+
print('Welcome to your personal telephone diary')
90+
request = int(input(welcome))
91+
match request:
92+
case 1:
93+
addContact = input('what about if we add some names on it before start, what is the name of the contact:')
94+
if addContact in telephoneDiary:
95+
print(" Be careful, It seems like that contact already exist")
96+
request = "wanna you do...\n" + welcome
97+
else:
98+
addNumber = input('yes, now what about if you tell me a number of this contact only ten numbers please: ')
99+
if addNumber.isdigit() == True and len(addNumber) == 10:
100+
addNumber = int(addNumber)
101+
telephoneDiary[addContact] = addNumber
102+
print(f'The contact: {addContact}, was added with the next number: {addNumber}')
103+
print(telephoneDiary)
104+
else:
105+
print('Only ten numbers please 🤨')
106+
case 2:
107+
searchContact = input('what is the exactly name, that we are looking forward: ')
108+
if searchContact in telephoneDiary:
109+
print(f'Here is your contact: {searchContact}', telephoneDiary[searchContact])
110+
else:
111+
print('Sorry but we can\'t find the contact')
112+
case 3:
113+
searchContact = input("What's the contact that you want to update: ")
114+
if searchContact in telephoneDiary:
115+
updateNumber = input('Tell me the new number: ')
116+
if updateNumber.isdigit() == True and len(updateNumber) == 10:
117+
updateNumber = int(updateNumber)
118+
telephoneDiary[searchContact] = updateNumber
119+
else: print('Only ten numbers 😤')
120+
else:
121+
print('Sorry but we can\'t find the contact')
122+
case 4:
123+
searchContact = input('What is the contact who you will get deleted from your list: ')
124+
if searchContact in telephoneDiary:
125+
telephoneDiary.pop(searchContact)
126+
print(f'the contact: {searchContact} was deleted')
127+
else:
128+
print('Sorry but we can\'t find the contact')
129+
case 5:
130+
conditional = False
131+
print(telephoneDiary)

0 commit comments

Comments
 (0)