Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # import pickle
- import pickle
- def view_results(classfile, classroom):
- # view scores (alphabetically, by highest score or by average score)
- while 1:
- print("Show %s" %(classroom))
- print("[1] In Alphabetical Order")
- print("[2] By Highest Score")
- print("[3] By Average Score")
- print("[4] Back to Rooms")
- choice = input("> ")
- if choice is '1':
- classfile.sort(key=lambda s: s[0], reverse=False)
- # sort alphabetically
- print("Sorted In Alphabetical Order")
- for i in classfile:
- score = sorted(i[1], reverse=True)
- # display the scores with the square brackets removed
- print(i[0].title() + '\t' + str(score).replace('[','').replace(']',''))
- input()
- # the problem is here ------------------------------------
- elif choice is '2':
- classfile.sort(key=lambda s: s[1], reverse=False)
- # by highest score
- print("Sorted By Highest Score")
- for i in classfile:
- score = sorted(i[1], reverse=True)
- # display the scores with the square brackets removed
- print(i[0].title() + '\t' + str(score).replace('[','').replace(']',''))
- input()
- # the problem is here -------------------------------------
- elif choice is '3':
- # by average score
- classfile.sort(key=lambda s: s[1], reverse=True)
- for i in classfile:
- # get the average and round it
- score = round(sum(i[1]) / 3)
- print(i[0].title() + '\t' + str(score))
- input()
- elif choice is '4':
- # go back to selection
- break
- else:
- pass
- # check for CLASS1.DAT
- try:
- classfile1 = pickle.load(open("class1.dat", 'rb'))
- except IOError:
- isClassroom1 = False
- else:
- isClassroom1 = True
- # check for CLASS2.DAT
- try:
- classfile2 = pickle.load(open("class2.dat", 'rb'))
- except IOError:
- isClassroom2 = False
- else:
- isClassroom2 = True
- # check for CLASS3.DAT
- try:
- classfile3 = pickle.load(open("class3.dat", 'rb'))
- except IOError:
- isClassroom3 = False
- else:
- isClassroom3 = True
- while 1:
- print("Primary School Arithmetic Quiz Viewer")
- print("Please choose a classroom: ")
- if bool(isClassroom1):
- print("[1] Classroom 1")
- else:
- print("file not found: CLASS1.DAT")
- if bool(isClassroom2):
- print("[2] Classroom 2")
- else:
- print("file not found: CLASS2.DAT")
- if bool(isClassroom3):
- print("[3] Classroom 3")
- else:
- print("file not found: CLASS3.DAT")
- print("[4] Exit")
- classfile = input("> ")
- if classfile is '1':
- if bool(isClassroom1):
- view_results(classfile1, "Classroom 1")
- else:
- pass
- elif classfile is '2':
- if bool(isClassroom2):
- view_results(classfile2, "Classroom 2")
- else:
- pass
- elif classfile is '3':
- if bool(isClassroom3):
- view_results(classfile3, "Classroom 3")
- else:
- pass
- elif classfile is '4':
- exit()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement