【问题标题】:EOF eror while running a script运行脚本时出现 EOF 错误
【发布时间】: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

【问题讨论】:

    标签: pycharm eof


    【解决方案1】:

    你使用的是什么版本的 Python?

    如果在 2.X 中,请尝试:

    move = raw_input("Enter 'go North/South/East/West' to move or 'Exit': ").split()[-1].capitalize()
    

    【讨论】:

    • 很高兴它成功了 :) 您可能需要上传您的 Python 版本,以避免将来出现其他问题。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2019-08-23
    • 2020-08-02
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-03-28
    相关资源
    最近更新 更多