Advertisement
Guest User

Untitled

a guest
Jan 20th, 2019
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.01 KB | None | 0 0
  1. #Esecizio Rubrica Spataro "Try Corretti"
  2.  
  3. def ins():
  4. nome=input("Inserisci il nome: ")
  5. cognome=input("Inserisci il cognome: ")
  6. numero=input("Inserisci il numero: ")
  7. mas=open("rubrica.txt","a")
  8. try:
  9. mas.write(nome)
  10. mas.write(",")
  11. mas.write(cognome)
  12. mas.write(",")
  13. mas.write(numero)
  14. mas.write(",\n")
  15. mas.close()
  16. except:
  17. print("Ops! C'è stato un errore inaspettato!")
  18.  
  19. def sta():
  20. try:
  21. mas=open("rubrica.txt")
  22. stampa=mas.read()
  23. print(stampa)
  24. print("\n")
  25. mas.close()
  26. except:
  27. print("Nella rubrica non ci sono ancora numeri salvati!")
  28.  
  29. def cer():
  30. import string
  31. try:
  32. mas=open("rubrica.txt")
  33. v=0
  34. inser=input("Inserisci il COGNOME di chi vuoi cercare: ")
  35. testo=mas.readlines()
  36. for i in range(len(testo)):
  37. if (inser in testo[i])==True:
  38. temp=testo[i].split(",")
  39. if (temp[1]==inser):
  40. print("\nInformazioni del contatto",inser,":")
  41. print(testo[i])
  42. v=1
  43. break
  44. if v==0:
  45. print("Il cognome",inser,"non è stato trovato nella tua rubrica!\n")
  46. except:
  47. print("Nella rubrica non ci sono ancora numeri salvati!")
  48.  
  49.  
  50.  
  51. def menu():
  52. aa="""\nInserisci:
  53. --------------------------------------------
  54. 1) Per inserire un contatto
  55. 2) Per stampare tutta la rubrica
  56. 3) Per cercare un contatto per cognome
  57.  
  58. 4) Per uscire
  59. --------------------------------------------
  60. """
  61. while True:
  62. print(aa)
  63. sc=9
  64. while (sc<1) or (sc>4):
  65. sc=int(input())
  66. if (sc<1) or (sc>4):
  67. print("Devi inserire 1,2,3 o 4!!")
  68. if sc==1:
  69. ins()
  70. elif sc==2:
  71. sta()
  72. elif sc==3:
  73. cer()
  74. elif sc==4:
  75. break
  76.  
  77. print("Benvenuto nella tua rubrica!")
  78. menu()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement