3

所以我的 Python 游戏中的这行代码不起作用:

direction=raw_input("What would you like to do?\n")

它应该让玩家输入命令:北、南、东、西、看、搜索、命令或库存。它提出了这个:

回溯(最近一次通话最后):文件“/Users/khalilismail/Desktop/COMPUTING/Text-based Games/DragonQuest.py”,第 173 行,方向=raw_input("What would you like to do?\n") EOFError : 读取一行时的 EOF

请帮忙

这是围绕此的代码堆栈:while game==on:

while place==town:

    direction=raw_input("What would you like to do?\n")

    if direction=="west":
        if "iron ore" and "wood" and "3 Gold Pieces" in items:
            print "The blacksmith greets you, and you tell him that you have the items and money he requires, you also give him the saw to make up for some of the difference, he then forges you a battleaxe and wishes you luck on the rest of your quest"
            items.remove ("saw")
            items.remove ("3 Gold Pieces")
            items.remove ("iron ore")
            items.remove ("wood")
            items.append ("battleaxe")
4

1 回答 1

0

正如评论中所建议的,一些编辑器不支持输入(包括 Atom)。以下是您可以克服的一些选项:

  1. 在调试时通过硬编码设置方向变量(调试后不要忘记将其删除)
  2. 更改您的编辑器(请记住,Sublime 也有同样的问题,但这有一个解决方法 - Sublime Text 2 控制台输入;但是 Notepad++ 在通过命令行运行代码时没有这个问题)。

您还可以尝试从 raw_input 字符串中删除换行符 '\n' 以测试它是否有效。

于 2015-05-21T12:37:21.820 回答