I need to be able to store results of a game in a file with names and high scores where I will eventually want to review the file and sort it alphabetically, etc. I'm unsure if I have the correct way of storing the results to be able to do this.
class_number = input('Please enter your class number: ')
from datetime import datetime
now = datetime.now()
time = ('%s/%s/%s %s:%s' % (now.day, now.month, now.year, now.hour, now.minute))
userscore = (user_name, ' ', str(total_score),' ', time, ' ')
if(int(class_number) == 1):
with open('class1.txt', 'a') as myFile:
myFile.writelines(userscore)
myFile.close()
elif(int(class_number) == 2):
with open('class2.txt', 'a') as myFile:
myFile.writelines(userscore)
myFile.close()
elif(int(class_number) == 3):
with open('class3.txt', 'a') as myFile:
myFile.writelines(userscore)
myFile.close()