Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/env python
- # -*- coding: utf-8 -*-
- """
- agenda telefonica
- ejercicio propuesto
- Opciones:
- 1. Agregar contacto
- 2. Modificar contacto
- 3. Consultar numero
- 4. Salir
- """
- # supongamos una persona, un telefono
- # agenda = {"Juan P":11225, "Ana G":44555}
- agenda = {}
- print("Agenda telefónica")
- while True:
- print("""
- Opciones:
- ---------------------
- 1. Agregar contacto
- 2. Modificar numero
- 3. Modificar nombre
- ---------------------
- 4. Consultar numero
- 5. Consultar nombre
- 6. Imprimir agenda
- ---------------------
- 7. Eliminar contacto
- 8. Salir
- """)
- opcion = input("Ingrese su opción: ")
- if opcion == "1":
- nombre = input("Ingrese el nombre del contacto: ")
- numero = input("Ingrese el nro de teléfono: ")
- agenda[nombre] = numero
- print("Contacto agregado")
- elif opcion == "2":
- nombre = input("Ingrese el nombre del contacto: ")
- nombres = list(agenda.keys())
- if nombre in nombres:
- numero = input("Ingrese el nuevo nro de teléfono: ")
- agenda[nombre] = numero
- print("Numero modificado")
- else:
- print(f"No existe el nombre {nombre}")
- elif opcion == "3":
- numero = input("Ingrese el numero del contacto: ")
- # borro el par nombre-viejo:numero
- borrado = False
- for k,v in agenda.items():
- if v == numero:
- del agenda[k]
- borrado = True
- break
- if borrado:
- nombre = input("Ingrese el nuevo nombre del contacto: ")
- agenda[nombre] = numero
- print("Nombre modificado")
- else:
- print(f"No existe el numero {numero}")
- elif opcion == "4":
- nombre = input("Ingrese el nombre del contacto: ")
- nombres = list(agenda.keys())
- if nombre in nombres:
- print(f"Teléfono: {agenda.get(nombre)}")
- else:
- print(f"No existe el contacto {nombre}")
- elif opcion == "5":
- numero = input("Ingrese el numero del contacto: ")
- hallado = False
- for k,v in agenda.items():
- if v == numero:
- print(f"Nombre: {k}")
- hallado = True
- break
- if not hallado:
- print(f"No existe el numero {numero}")
- elif opcion == "6":
- if agenda:
- for k,v in agenda.items():
- print(f"nombre: {k} - telefono: {v}")
- else:
- print("Agenda vacía")
- elif opcion == "7":
- nombre = input("Ingrese el nombre del contacto: ")
- nombres = list(agenda.keys())
- if nombre in nombres:
- del agenda[nombre]
- print("Contacto eliminado")
- else:
- print(f"No existe el contacto {nombre}")
- elif opcion == "8":
- print("Adiós...")
- break
- else:
- print("Opción incorrecta...")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement