Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- massimo_punti = [25,25,50,25,100]
- assignments = ['Biologia', 'Chimica', 'Lettere','Matematica','Informatica']
- students = { "Studente" : massimo_punti}
- def save_grades(fileName):
- f = open(fileName + ".txt", 'w')
- keys = students.keys()
- keys.sort()
- for x in keys:
- f.write(x)
- f.write("\n")
- f.write(' '.join(map(str, students[x]))) #converte gli elementi della lista students[x] (massimo_punti) in stringhe (map str) e le unisce (' '.join())
- f.write("\n")
- f.close()
- def menu():
- print "1. Aggiungi uno studente"
- print "2. Rimuovi uno studente"
- print "3. Visualizza voti"
- print "4. Registra voti"
- print "5. Visualizza menu"
- print "6. Salva voti"
- print "7. Esci"
- def stampa_tutti_voti():
- print '\t'
- for i in range(len(assignments)):
- print assignments[i],'\t',
- print
- keys = students.keys()
- keys.sort()
- for x in keys:
- print x,'\t',
- grades = students[x]
- print_grades(grades)
- def print_grades(grades):
- for i in range(len(grades)):
- print grades[i],'\t\t',
- print
- menu()
- menu_choice = 0
- while menu_choice != 7:
- print
- menu_choice = input("Scegli (1-7): ")
- if menu_choice == 1:
- name = raw_input("Studente da aggiungere:")
- students[name] = [0]*len(massimo_punti)
- elif menu_choice == 2:
- name = raw_input("Studenti da rimuovere:")
- if students.has_key(name):
- del students[name]
- else:
- print "Student: ", name, " not found"
- elif menu_choice == 3:
- stampa_tutti_voti()
- elif menu_choice == 4:
- print "Registra voto"
- name = raw_input("Studente:")
- if students.has_key(name):
- grades = students[name]
- print "Digita il voto da registrare"
- print "Digita 0 per uscire"
- for i in range(len(assignments)):
- print i+1,' ',assignments[i],'\t',
- print
- print_grades(grades)
- which =1234
- while which != -1:
- which = input("cambia quale voto:")
- which = which-1
- if 0 <= which < len(grades):
- grade = input("voto:")
- grades[which] = grade
- elif which != -1 :
- print "Voto non valido"
- else:
- print "Studente non trovato"
- elif menu_choice == 5:
- menu()
- elif menu_choice == 6:
- filename = raw_input("Come vuoi chiamare il file?")
- save_grades(filename)
- elif menu_choice != 7:
- break
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement