定義我爲我的基於文本的遊戲的代碼和我收到一個錯誤說Python的NameError:名字「北」不是文字遊戲
line 1, in <module>
userInput = input("Please enter a direction in which to travel: ")
File "<string>", line 1, in <module>
NameError: name 'north' is not defined
這裏是我的代碼
userInput = input("Please enter a direction in which to travel: ")
Map = {
'north':'that way leads to the kitchen',
'south':'that way leads to the dining room',
'east':'that way leads to the entry',
'west':'that way leads to the living room'
}
if userInput == north:
print Map['north']
elif userInput == south:
print Map['south']
elif userInput == east:
print Map['east']
elif userInput == West:
print Map['west']
elif userInput == '':
print "Please specify a various direction."
else:
quit
感謝您的幫助
如果這實際上是你的代碼,你承擔責任後,你收到了很多IndentationErrors'的'在你的指示周圍放置一些引號,使它們成爲字符串。 – roippi
問題在於你的if語句,但你也可以大大簡化。在下面檢查我的答案。我提供了工作代碼。 –
另外,python中沒有'quit'關鍵字。 – SethMMorton