我正在尝试创建几个分支,这一直给我这个名称错误
我试着删除它给我带来的问题,然后我想我是在删除整件事
while True:
d1a = input ("Do you want to: A) Approach the house. B) Approach the stable. [A/B]? : ")
# check if d1a is equal to one of the strings, specified in the list
if d1a in ['A', 'B']:
# if it was equal - break from the while loop
break
if d1a == "A":
print ("You approach the cottage.")
elif d1a == "B":
print ("You approach the stables.")
错误:回溯(最近一次呼叫上次): 文件“main.py”,第5行,在 d1a=输入(“你想:A)接近房子。B) 接近马厩[A/B]?:”) 文件“”,第1行,在 NameError:未定义名称“A”
看起来您正在运行Python 2,也称为遗留Python。在该版本的Python中,
input
尝试评估输入。您输入了A
,因此Python试图找到它的值。没有名为A
的变量,因此您收到了错误消息用
raw_input
代替input
。或者更好的是,转到Python3。您的代码在我的Python3.7.3中运行良好相关问题 更多 >
编程相关推荐