gpt4 book ai didi

python - python 中未识别错误名称

转载 作者:太空宇宙 更新时间:2023-11-03 17:48:19 25 4
gpt4 key购买 nike

我正在创建一些代码,我可以将数据分类为不同的类别,例如将数据按字母顺序排序。我将测试的分数存储在 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)

最佳答案

我想你想要

class_name = input('Which class?:')
class_name = int(class_)

成为

class_name = int(input('Which class?:'))

然后使用if class_name==1:

关于python - python 中未识别错误名称,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29449947/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com