我正在尝试编写一个简单的Letter Grade Converter,它从0到100输入并返回一个字母等级。 while语句的结束要求y / n输入继续转换或结束转换。输入Y似乎总是返回y尚未定义的名称错误。
print("Letter Grade Converter")
choice = "y"
while choice.lower() == "y":
number = int(input("Enter numerical grade: "))
if number > 87:
letter = "A"
elif number > 79:
letter = "B"
elif number > 66:
letter = "C"
elif number > 59:
letter = "D"
else:
letter = "F"
print("Letter Grade: " + letter)
choice = input("Continue (y/n)?: ")
print ("Bye!")
我已经在开头定义了选项,是什么导致了名称错误?