#Variable containing the users class
Classes = ["classa","classb","classc"]
#Creates a variable so the textfile for ClassA can be opened.
OpenA = open ("ClassA.txt","a")
#Creates a variable so the textfile for ClassB can be opened.
OpenB = open ("ClassB.txt","a")
#Creates a variable so the textfile for ClassC can be opened.
OpenC = open ("ClassC.txt","a")
while True:
Class = input("What class' results would you like to see?(ClassA, ClassB or ClassC)")
#User friendly accepts the users answer if it is in higher or lower case
Class = Class.lower()
#Checks if the class provided by the user is from the three classes which have been provided
if Class.lower() in Classes:
#Leaves the while loop if all the conditions have been met
break
else:
#Tells the user that the class which they had inputed was not correct
print("Invalid, please choose a class from the list provided!")
if Class.lower() == ("classa"):
print("Showing results for ClassA")
elif Class.lower() == ("classb"):
print("Showing results for class B")
else:
print("Showing results for class C")
The above code is the code which I have created so far to complete this task.
The main part in which I need help is creating a dictionary as the system should store the last three scores for each student. It will then also need to sort the results from the text files alphabetically, highest to lowest and by average. However, I do not know how to do this especially when dictionaries are involved. Would appreciate explanation with results to ensure that I am able to learn from this.