@@ -105,58 +105,114 @@ def limpiar(): # Como si voy ejecutando más de una vez me "ensucia" la terminal
105
105
print (f"Ahora mi_Diccionario tiene los elementos: { mi_Diccionario } \n " )
106
106
107
107
"""
108
- Agenda
108
+ AGENDA
109
109
"""
110
- print ("++++++++++++++++++++++++++++++++++++++++++" )
111
- print (" A G E N D A\n " )
112
- print ("++++++++++++++++++++++++++++++++++++++++++" )
110
+
113
111
agenda = {}
114
- while True : # iniciamos la consulta de que quiere hacer el usuario
115
-
116
- print ("1- Busqueda de un contacto\n " )
117
- print ("2- Inserción de un contacto\n " )
118
- print ("3- Actualización de un contacto\n " )
119
- print ("4- Eliminación de un contacto\n " )
120
-
121
- entrada = input ("escribe opción: \n " )
122
- if agenda == {} and (entrada == "1" or entrada == "3" or entrada == "4" ):
123
- print ("la agenda está vacia\n " )
124
- continue
125
- elif entrada == "1" or entrada == "2" or entrada == "3" or entrada == "4" :
126
- print ("procesando\n " )
127
- break
128
- else :
129
- print ("no has escogido correctamente" )
130
-
131
- # Gestionamos la opción decidia
132
-
133
- if entrada == "1" : # Busqueda de contacto
134
- nombre = input ("nombre: " )
135
- elemento = agenda .get (nombre )
136
- if elemento == None :
137
- print ("no existe contacto" )
138
-
139
- elif entrada == "2" : # Introducción de contacto
140
- nombre = input ("nombre: " )
141
- apellidos = input ("apellidos: " )
142
- telefono = input ("teléfono: " )
143
- agenda [nombre ] = [apellidos , telefono ]
144
-
145
-
146
- elif entrada == "3" : # solicitamos que contacto quiere actualizar y el que
147
-
148
- while True :
112
+ while True :
113
+ while True : # iniciamos la consulta de que quiere hacer el usuario
114
+ limpio = input ("limpio la pantalla? (si) o (no): " )
115
+ if limpio == "si" :
116
+ limpiar ()
117
+ elif limpio == "no" :
118
+ pass
119
+ print ("\n " )
120
+ print ("++++++++++++++++++++++++++++++++++++++++++" )
121
+ print (" A G E N D A\n " )
122
+ print ("++++++++++++++++++++++++++++++++++++++++++\n " )
123
+ print ("1- Busqueda de un contacto\n " )
124
+ print ("2- Inserción de un contacto\n " )
125
+ print ("3- Actualización de un contacto\n " )
126
+ print ("4- Eliminación de un contacto\n " )
127
+ print ("5- Listado de contactos\n " )
128
+ print ("6- EXIT\n " )
129
+
130
+ entrada = input ("escribe opción: \n " )
131
+ if agenda == {} and (entrada == "1" or entrada == "3" or entrada == "4" or entrada == "5" ):
132
+ print ("la agenda está vacia\n " )
133
+ continue
134
+ elif entrada == "1" or entrada == "2" or entrada == "3" or entrada == "4" or entrada == "5" or entrada == "6" :
135
+ print ("procesando\n " )
136
+ break
137
+ else :
138
+ print ("no has escogido correctamente" )
139
+
140
+ # Gestionamos la opción decidia
141
+
142
+ if entrada == "1" : # OPCIÓN 1- Busqueda de contacto
143
+ nombre = input ("nombre: " )
144
+ elemento = agenda .get (nombre )
145
+ if elemento == None :
146
+ print ("no existe contacto" )
147
+ else :
148
+ print (elemento )
149
+
150
+ elif entrada == "2" : # OPCIÓN 2- Introducción de contacto
151
+ print ("introducimos un nuevo contacto\n " )
152
+ nombre = input ("nombre: " )
153
+ apellidos = input ("apellidos: " )
154
+ telefono = input ("teléfono: " )
155
+ agenda [nombre ] = [apellidos , telefono ]
149
156
150
- nombre = input ("dame el nombre del contacto a actualizar" )
151
- print ("que quieres realizar: \n " )
152
- print ("1- actualizar nombre: \n " )
153
- print ("2- actualizar apellidos: \n " )
154
- print ("3- actualizar telefono: \n " )
155
- opcion = input ("escribe la opción: " )
156
-
157
- if opcion == "1" :
158
- if nombre in agenda :
159
- nuevo_contacto = agenda .pop (nombre )
160
- agenda [nombre ]= nuevo_contacto
161
- print (agenda )
162
- break
157
+
158
+ elif entrada == "3" : # OPCIÓN 3- solicitamos que contacto quiere actualizar y el que
159
+ bucle = True
160
+ while bucle :
161
+
162
+ nombre = input ("dame el nombre del contacto a actualizar: " )
163
+ print ("que quieres realizar: \n " )
164
+ print ("1- actualizar nombre: \n " )
165
+ print ("2- actualizar apellidos: \n " )
166
+ print ("3- actualizar telefono: \n " )
167
+ print ("4- volver" )
168
+ opcion = input ("escribe la opción: " )
169
+
170
+ if opcion == "1" :
171
+ if nombre in agenda :
172
+ nuevo_contacto = agenda .pop (nombre )
173
+ nuevo_nombre = input ("introduce el nuevo nombre: " )
174
+ agenda [nuevo_nombre ]= nuevo_contacto
175
+ apellidos_diccionario = agenda .get (nuevo_nombre )
176
+ print ("contacto actualizado: " ,nuevo_nombre ,* apellidos_diccionario )
177
+ bucle = False
178
+ elif opcion == "2" :
179
+ if nombre in agenda :
180
+ nuevo_apellido = input ("introduce los apellidos: \n " )
181
+ valores = agenda .get (nombre )
182
+ tel = valores [1 ]
183
+ agenda [nombre ]= [nuevo_apellido ,tel ]
184
+ valores = agenda .get (nombre )
185
+ print ("contacto actualizado: " ,nombre , * valores )
186
+ elif opcion == "3" :
187
+ if nombre in agenda :
188
+ nuevo_telefono = input ("introduce el nuevo teléfono: \n " )
189
+ valores = agenda .get (nombre )
190
+ apell = valores [0 ]
191
+ agenda [nombre ]= [apell ,nuevo_telefono ]
192
+ valores = agenda .get (nombre )
193
+ print ("contacto actualizado: " ,nombre , * valores )
194
+ bucle = False
195
+ elif opcion == "4" :
196
+ bucle = False
197
+ elif entrada == "4" : # OPCIÓN 4- solicitamos que contacto quiere eliminar
198
+ bucle = True
199
+ while bucle :
200
+ contacto_elim = input ("dame el nombre del contacto a eliminar: " )
201
+ if contacto_elim in agenda :
202
+ alerta = input ("estas seguro que quieres borrar el contacto?? (si - no): " )
203
+ if alerta == "si" :
204
+ agenda .pop (contacto_elim )
205
+ print ("contacto eliminado\n " )
206
+ bucle = False
207
+ elif alerta == "no" :
208
+ bucle = False
209
+ elif entrada == "5" : # listamos los contactos
210
+ bucle = True
211
+ for clave in agenda :
212
+ valores = agenda .get (clave )
213
+ print (clave ,* valores )
214
+ bucle = False
215
+ elif entrada == "6" :
216
+ break
217
+
218
+
0 commit comments