Created
September 15, 2013 15:30
-
-
Save anonymous/6571779 to your computer and use it in GitHub Desktop.
Libro de direcciones con funciones de:
-Añadir contacto
-Buscar contacto
-Mostrar todos los contactos
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def baseDatos(info): #Añade los datos de recolectar() a el documento | |
doc = open('hola.txt','a') | |
doc.write(info) | |
doc.write('\n') | |
def recolectar(): | |
name = input('Nombre: ') | |
ap = input('Apellido: ') | |
op = input('Apellido2 u Opcional: ') | |
num = input('Número: ') | |
dirr = input('Dirección: ') | |
email = input('Email: ') | |
datos = name + ', ' + ap + ', ' + op + ', ' + num + ', ' + dirr + ', ' + email | |
baseDatos(datos) | |
def buscar(): | |
doc = open('hola.txt', 'r') | |
busqueda = input('Palabra clave a buscar: ') | |
for line in doc: | |
if busqueda in line: | |
print(line) | |
else: | |
print('No se encontró el contacto.') | |
def mostrarTodos(): | |
doc = open('hola.txt', 'r') | |
leer = doc.read() | |
print(leer) | |
def menu(): | |
print('- - - - A G E N D A - - - -') | |
print('Elegir una opción:') | |
f = input('Crear contacto [1]\nBuscar contacto [2]\nMostrar todos [3] ') | |
if f == '1': | |
recolectar() | |
elif f == '2': | |
buscar() | |
elif f == '3': | |
mostrarTodos() | |
else: | |
print('Esa no es una opción válida (REINICIANDO') | |
menu() | |
run = True | |
while run: | |
menu() | |
res = input('Quieres volver a usar la agenda? ') | |
if res.startswith('s'): | |
run = True | |
else: | |
run = False |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment