我创建了一些代码,我可以将数据分类到不同的类别,例如将数据按字母顺序排序。我有一个测试的分数存储在3个不同的txt文件中,我需要阅读它们然后将其打印到订单中。但是在我的代码中,它表示名称class_未定义。有什么帮助吗?
loop = 1
while loop ==1:
print("Welcome, you can sort the data from the scores by...")
print("The following...")
print()
print("Option 1) sort score by alphabetically")
print("Option 2) sort by average score- high to low")
print("Option 3) sort by highest score- high to low")
print("Option 5) Exit")
choice = input("Select your option: ")
choice = int(choice)
if choice ==1:
print("option 1 selected... Alphabetically")
class_name = input('Which class?:')
class_name = int(class_)
if class_==1:
open('class_1', 'r')
lineList = inputFile.readlines()
lineList.sort()
print('The input in alphabetical order below :')
for line in lineList:
print(line)
答案 0 :(得分:1)
我想你想要
class_name = input('Which class?:')
class_name = int(class_)
要
class_name = int(input('Which class?:'))
然后使用if class_name==1: