【发布时间】:2021-03-17 12:32:00
【问题描述】:
我正在做一个简单的游戏项目,这部分是您在房间之间移动的部分。此代码在 PYthonTutot 中有效,但在 Pycharm 中无效。我错过了什么?提前谢谢你
#简化龙文字游戏的字典 #字典将一个房间链接到其他房间。 房间 = { '大厅':{'南':'卧室'}, '卧室':{'北':'大厅','东':'地窖'}, “地窖”:{“西”:“卧室”} }
# Let's start from the Great Hall
starting_room = 'Great Hall'
# set current room to use in the gameplay loop
current_room = starting_room
while True:
print("\nYou are currently in {}".format(current_room))
# let the user enter a command to move as 'go direction' or 'exit'
# first we split the input by space, then take the last part, capitalize first letter
# if 'go direction' ==> 'Direction'
# if 'exit' ==> 'Exit'
move = input("Enter 'go North/South/East/West' to move or 'Exit': ").split() [-1].capitalize()
# user to exit
if move == 'Exit':
current_room = 'exit'
break
elif move in rooms[current_room]: # a valid move
current_room = rooms[current_room][move]
# invalid move
else:
print("Invalid Move. There's no room to the {}".format(move))
You are currently in Great Hall
Enter 'go North/South/East/West' to move or 'Exit': go south
Traceback (most recent call last):
File "/Users/tanyapryma/PycharmProjects/pythonProject2/main.py", line 36, in <module>
move = input("Enter 'go North/South/East/West' to move or 'Exit': ").split()[-1].capitalize()
文件“”,第 1 行 向南走 ^ SyntaxError: 解析时出现意外的 EOF
【问题讨论】: