Bir .csv dosyasına ayrılan sonuçlarla bir sınavım var, sorular yanıtlandıktan sonra, kullanıcılardan sonuçların alfabetik olarak mı yoksa en düşüğe doğru en alta mı sorulması gerektiğini sorar. Bu soru daha sonra cevap girilirse tekrarlanır, ancak alfabetik olarak en az birkaç kez en düşük değere girilirse çalışır.Yinelenen bir csv içinde nasıl sıralanacağını sorma
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")
I = alfabetik alfa sonrasında mola ekledik ve onu takip ne şimdi iki kez soruyu sorar ve ikinci kez bunu anlatıyor neyse. – SamH314