Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #Esecizio Rubrica Spataro "Try Corretti"
- def ins():
- nome=input("Inserisci il nome: ")
- cognome=input("Inserisci il cognome: ")
- numero=input("Inserisci il numero: ")
- mas=open("rubrica.txt","a")
- try:
- mas.write(nome)
- mas.write(",")
- mas.write(cognome)
- mas.write(",")
- mas.write(numero)
- mas.write(",\n")
- mas.close()
- except:
- print("Ops! C'è stato un errore inaspettato!")
- def sta():
- try:
- mas=open("rubrica.txt")
- stampa=mas.read()
- print(stampa)
- print("\n")
- mas.close()
- except:
- print("Nella rubrica non ci sono ancora numeri salvati!")
- def cer():
- import string
- try:
- mas=open("rubrica.txt")
- v=0
- inser=input("Inserisci il COGNOME di chi vuoi cercare: ")
- testo=mas.readlines()
- for i in range(len(testo)):
- if (inser in testo[i])==True:
- temp=testo[i].split(",")
- if (temp[1]==inser):
- print("\nInformazioni del contatto",inser,":")
- print(testo[i])
- v=1
- break
- if v==0:
- print("Il cognome",inser,"non è stato trovato nella tua rubrica!\n")
- except:
- print("Nella rubrica non ci sono ancora numeri salvati!")
- def menu():
- aa="""\nInserisci:
- --------------------------------------------
- 1) Per inserire un contatto
- 2) Per stampare tutta la rubrica
- 3) Per cercare un contatto per cognome
- 4) Per uscire
- --------------------------------------------
- """
- while True:
- print(aa)
- sc=9
- while (sc<1) or (sc>4):
- sc=int(input())
- if (sc<1) or (sc>4):
- print("Devi inserire 1,2,3 o 4!!")
- if sc==1:
- ins()
- elif sc==2:
- sta()
- elif sc==3:
- cer()
- elif sc==4:
- break
- print("Benvenuto nella tua rubrica!")
- menu()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement