Ich habe ein Quiz mit Ergebnissen, die in eine CSV-Datei sortiert sind, nach der Beantwortung der Fragen fragt der Benutzer, ob die Ergebnisse alphabetisch oder nach höchsten bis niedrigsten sortiert werden sollen. Diese Frage wird dann wiederholt, unabhängig von der eingegebenen Antwort. Wenn jedoch die höchste oder die niedrigste eingegeben wird, wird sie alphabetisch wiederholt.Fragen, wie in einem csv zu sortieren, wird wiederholt
print ("Would you like to see the results alphabetically or by highest to lowest?")
alpha = input()
while alpha != "alphabetically":
alpha = str(input ("Would you like to see the results alphabetically or by highest to lowest? "))
break
while alpha != "highest to lowest":
alpha = str(input ("Would you like to see the results alphabetically or by highest to lowest? "))
break
def updatefile(file,sortby,Classnumber): #this shortens the code by about 3 lines per file update
if Class == Classnumber:
with open(file,'a') as f:
file_writer = csv.writer(f, delimiter = ',', lineterminator='\n')
file_writer.writerow((name,score))
sortcsv(file,sortby)
if alpha == "alphabetically":
updatefile('Class 1 Results.csv',0,"1") #saves space using shortened code, makes the code use alphabetical sorting
updatefile('Class 2 Results.csv',0,"2")
updatefile('Class 3 Results.csv',0,"3")
elif alpha == "highest to lowest":
updatefile('Class 1 Results.csv',1,"1") #makes the code use highest to lowest sorting
updatefile('Class 2 Results.csv',1,"2")
updatefile('Class 3 Results.csv',1,"3")
Ich habe eine Pause nach alpha! = Alphabetisch hinzugefügt und was folgt, jetzt stellt es die Frage zweimal und macht alles, was Sie ihm zum zweiten Mal sagen. – SamH314