Is there any way I could tidy this code and make it look better and more appealing?
import csv math_class = input ("Which math class would you like to see the results of?") while math_class not in ['1','2','3']: math_class = input ("Which math class would you like to see the results of?") sort = input ("How would you like to sort the results alphabetical, highest or average:\n") while sort not in ["alphabetical","highest","average"]: sort = input ("How would you like to sort the results") class_file_names = ['Class 1.csv', 'Class 2.csv', 'Class 3.csv'] scan = open(class_file_names[int(math_class)-1], 'r+') rows = csv.reader(scan) data =  next(scan) for row in rows: data.append(row) scan.close() if(sort == "alphabetical"): word = "- Highest Score on test:" sorted_= sorted(data, key=lambda name: name ) field = 5 if(sort == "average"): word = "- Average Score" sorted_ = sorted(data, key=lambda average: average, reverse=True) field = 4 if(sort == "highest"): word = "- Highest Score on test:" sorted_ = sorted(data, key=lambda total: total, reverse=True) field = 5 for row in sorted_: print(str(row), word, str(row[field])) input ("Sort Complete, press any key to close the program.")
If there is no way I could clean up the code, then that's fine as it does what I want it to (it's just that I thought the code could look more appealing than it already is).