我对Python3相当陌生,但我正在制作一个简单的程序,在这个程序中我可以选择一个学生的班级,并选择根据平均值、最高分数等显示他们的分数。。。我想知道的是如何返回到代码的开头,这样我就可以选择另一个类,并检查另一组信息,例如B类平均分数。我想知道如何才能返回代码的开头。谢谢你的时间我很感激。在
注:我删去了部分代码import csv
print("1 for Class A\n2 for Class B\n3 for Class C")
choosen=int(input())
class_a = open('class_a.txt')
class_b = open('class_b.txt')
class_c = open('class_c.txt')
if choosen == 1:
print("1 for for alphabetical orderwith each students highest score\n2 for highest score, highest to lowest\n3 for average score, highest to lowest")
cho_two=int(input())
csv_a = csv.reader(class_a)
a_list = []
for row in csv_a:
row[3] = int(row[3])
row[4] = int(row[4])
row[5] = int(row[5])
minimum = min(row[3:5])
row.append(minimum)
maximum = max(row[3:5])
row.append(maximum)
average = sum(row[3:5])//3
row.append(average)
a_list.append(row[0:9])
if cho_two == 1:
alphabetical = [[x[0],x[6]] for x in a_list]
print("\nCLASS A\nEach students highest by alphabetical order \n")
for alpha_order in sorted(alphabetical):
print(alpha_order)
class_a.close()
elif cho_two == 2:
print("\nCLASS A\nThe highest score to the lowest \n")
for high_scr in sorted(highest_score,reverse = True):
print(high_scr)
class_a.close()
elif cho_two == 3:
average_score = [[x[8],x[0]] for x in a_list]
print("\nCLASS A\nThe average score from highest to lowest \n")
for ave_scr in sorted(average_score,reverse = True):
print(ave_scr)
class_a.close()
代码运行示例
^{pr2}$