Python 3.5语法错误,ParseError:输入错误

时间:2016-05-18 17:22:22

标签: python python-3.x pygame

我正在编写一个python游戏,我一直在犯错误

define_direction( DOWN, "down" )
ParseError: bad input

SyntaxError:语法无效(< string>,第115行)

我正在使用http://www.pythontutor.com/visualize.html

原始基本代码:http://blog.trinket.io/python-text-adventure/

我不明白当其他所有工作时它是如何无效的语法。我该如何解决这个错误。 任何机构都有关于如何处理文本冒险游戏中的移动和方向的任何建议。

# A "direction" is all the ways you can describe going some way
directions = {}
direction_name = {}

# These are code-visible canonical names for directions for adventure authors
NORTH = 1
SOUTH = 2
EAST = 3
WEST = 4
NORTH_EAST = 5
NORTH_WEST = 6
SOUTH_EAST = 7
SOUTH_WEST = 8
UP = 9
DOWN = 10
RIGHT = 11
LEFT = 12
IN = 13
OUT = 14
FORWARD = 15
BACK = 16
NOT_DIRECTION = -1

# map direction names to direction numbers
def define_direction( number, name ):
  # check to see if we are trying to redefine an existing direction
  if name in directions:
    print(name, "is already defined as,", directions[name])
  directions[name] = number
  if not number in direction_name or (len(direction_name[number]) < len(name)):
    direction_name[number] = name

# define player words used to describe known directions

# Cardinal Directions

# Northern Directions
define_direction( NORTH, "n" )
define_direction( NORTH, "north" )
define_direction( NORTH, "northmost" )
define_direction( NORTH, "northern" )
define_direction( NORTH, "northward" )
define_direction( NORTH, "northernly" )
define_direction( NORTH, "northbound" )

# Southern Directions
define_direction( SOUTH, "s" )
define_direction( SOUTH, "south" )
define_direction( SOUTH, "southmost" )
define_direction( SOUTH, "southern" )
define_direction( SOUTH, "southward" )
define_direction( SOUTH, "southernly" )
define_direction( SOUTH, "southbound" )

# Eastern Directions
define_direction( EAST, "e" )
define_direction( EAST, "east" )
define_direction( EAST, "eastmost" )
define_direction( EAST, "eastern" )
define_direction( EAST, "eastward" )
define_direction( EAST, "seasternly" )
define_direction( EAST, "eastbound" )

# Western Directions
define_direction( WEST, "w" )
define_direction( WEST, "west" )
define_direction( WEST, "westmost" )
define_direction( WEST, "western" )
define_direction( WEST, "westward" )
define_direction( WEST, "westernly" )
define_direction( WEST, "westbound" )

# Northeast Directions
define_direction( NORTH_EAST, "ne" )
define_direction( NORTH_EAST, "northeastmost" )
define_direction( NORTH_EAST, "northeastern" )
define_direction( NORTH_EAST, "northeastward" )
define_direction( NORTH_EAST, "northeasternly" )
define_direction( NORTH_EAST, "northeastbound" )

# Northwestern Directions
define_direction( NORTH_WEST, "nw" )
define_direction( NORTH_WEST, "northwestmost" )
define_direction( NORTH_WEST, "northwestern" )
define_direction( NORTH_WEST, "northwestward" )
define_direction( NORTH_WEST, "northwesternly" )
define_direction( NORTH_WEST, "northwestbound" )

# Southeastern Directions
define_direction( SOUTH_EAST, "se" )
define_direction( SOUTH_EAST, "southeastmost" )
define_direction( SOUTH_EAST, "southeastern" )
define_direction( SOUTH_EAST, "southeastward" )
define_direction( SOUTH_EAST, "southeasternly" )
define_direction( SOUTH_EAST, "southeastbound" )

# Southhwestern Directions
define_direction( SOUTH_WEST, "sw" )
define_direction( SOUTH_WEST, "southwestmost" )
define_direction( SOUTH_WEST, "southwestern" )
define_direction( SOUTH_WEST, "southwestward" )
define_direction( SOUTH_WEST, "southwesternly" )
define_direction( SOUTH_WEST, "southwestbound" )

# X,Y Direction Directions

# Upward Directions
define_direction( UP, "up" )
define_direction( UP, "u" )
define_direction( UP, "upward" )
define_direction( UP, "top" )
define_direction( UP, "above" 

# Downward Directions
define_direction( DOWN, "down" )
define_direction( DOWN, "d" )
define_direction( DOWN, "downward" )
define_direction( DOWN, "bottom" )
define_direction( DOWN, "below" )

# Right Direction
define_direction( RIGHT, "right" )
define_direction( RIGHT, "rightmost" )
define_direction( RIGHT, "rightern" )
define_direction( RIGHT, "rightward" )
define_direction( RIGHT, "rightbound" )


# Left Direction
define_direction( LEFT, "left" )
define_direction( LEFT, "leftmost" )
define_direction( LEFT, "leftern" )
define_direction( LEFT, "leftward" )
define_direction( LEFT, "leftbound" )

# Directions

define_direction( IN, "in" )
define_direction( OUT, "inward" )

define_direction( OUT, "out" )
define_direction( OUT, "outward" )

# Continued Direction
define_direction( FORWARD, "forward" )
define_direction( FORWARD, "fd" )
define_direction( FORWARD, "fwd" )
define_direction( FORWARD, "f" )
define_direction( FORWARD, "forth" )
define_direction( FORWARD, "onward" )
define_direction( FORWARD, "advance" )

# Return to previous Direction
define_direction( BACK, "backward" )
define_direction( BACK, "back" )
define_direction( BACK, "bck" )
define_direction( BACK, "bk" )
define_direction( BACK, "b" )
define_direction( BACK, "away" )
define_direction( BACK, "retreat" )
define_direction( BACK, "return" )

修正了谢谢wim !!

解 &#34;你错过了前一行的右括号:

define_direction(UP,&#34;以上&#34; 当python抱怨语法错误时,通常会在它实际抱怨的行之前查看该行。&#34;

1 个答案:

答案 0 :(得分:3)

您错过了上一行的右括号:

define_direction( UP, "above" 

当python抱怨语法错误时,通常会在它实际抱怨的行之前查看该行。