Advertisement
Guest User

Esercizio Voti

a guest
Jan 2nd, 2014
63
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.21 KB | None | 0 0
  1. massimo_punti =  [25,25,50,25,100]
  2. assignments = ['Biologia', 'Chimica', 'Lettere','Matematica','Informatica']
  3. students = { "Studente" : massimo_punti}
  4.  
  5. def save_grades(fileName):
  6.     f = open(fileName + ".txt", 'w')
  7.     keys = students.keys()
  8.     keys.sort()
  9.     for x in keys:
  10.         f.write(x)
  11.         f.write("\n")
  12.         f.write(' '.join(map(str, students[x]))) #converte gli elementi della lista students[x] (massimo_punti) in stringhe (map str) e le unisce (' '.join())
  13.         f.write("\n")
  14.     f.close()
  15.    
  16. def menu():
  17.     print "1. Aggiungi uno studente"
  18.     print "2. Rimuovi uno studente"
  19.     print "3. Visualizza voti"
  20.     print "4. Registra voti"
  21.     print "5. Visualizza menu"
  22.     print "6. Salva voti"
  23.     print "7. Esci"
  24.  
  25. def stampa_tutti_voti():
  26.     print '\t'
  27.     for i in range(len(assignments)):
  28.         print assignments[i],'\t',
  29.     print
  30.     keys = students.keys()
  31.     keys.sort()
  32.     for x in keys:
  33.         print x,'\t',
  34.         grades = students[x]
  35.         print_grades(grades)
  36.  
  37.  
  38. def print_grades(grades):
  39.     for i in range(len(grades)):
  40.         print grades[i],'\t\t',
  41.     print
  42.  
  43. menu()
  44. menu_choice = 0
  45. while menu_choice != 7:
  46.     print
  47.     menu_choice = input("Scegli (1-7): ")
  48.     if menu_choice == 1:
  49.         name = raw_input("Studente da aggiungere:")
  50.         students[name] = [0]*len(massimo_punti)
  51.     elif menu_choice == 2:
  52.         name = raw_input("Studenti da rimuovere:")
  53.         if students.has_key(name):
  54.             del students[name]
  55.         else:
  56.             print "Student: ", name, " not found"
  57.     elif menu_choice == 3:
  58.          stampa_tutti_voti()
  59.     elif menu_choice == 4
  60.         print "Registra voto"
  61.         name = raw_input("Studente:")
  62.         if students.has_key(name):
  63.             grades = students[name]
  64.             print "Digita il voto da registrare"
  65.             print "Digita 0 per uscire"
  66.             for i in range(len(assignments)):
  67.                 print i+1,' ',assignments[i],'\t',
  68.             print
  69.             print_grades(grades)
  70.             which =1234
  71.             while which != -1:
  72.                 which = input("cambia quale voto:")
  73.                 which = which-1
  74.                 if 0 <= which < len(grades):
  75.                     grade = input("voto:")
  76.                     grades[which] = grade
  77.                 elif which != -1 :
  78.                     print "Voto non valido"
  79.         else:
  80.             print "Studente non trovato"
  81.     elif menu_choice == 5:
  82.         menu()
  83.     elif menu_choice == 6:
  84.         filename = raw_input("Come vuoi chiamare il file?")
  85.         save_grades(filename)
  86.     elif menu_choice != 7:
  87.         break
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement