Ich bin ein Python-Spiel zu schreiben, halte ich Fehler auf immerPython 3.5 Syntaxfehler, ParseError: bad Eingang
define_direction(DOWN, "down")
ParseError: bad input
Syntax: ungültige Syntax (< string>, Zeile 115)
Ich bin mit http://www.pythontutor.com/visualize.html
Original-Base-Code: http://blog.trinket.io/python-text-adventure/
ich verstehe nicht, wie es eine ungültige Syntax ist, wenn alles andere funktioniert. Wie behebe ich diesen Fehler? Jeder Körper hat irgendwelche Vorschläge, wie man mit Bewegung und Richtung in einem anderen Text-Adventure-Spiel umgehen kann.
# 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")
Fixed Danke wim !!
Lösung „Sie fehlt eine schließende Klammer in der vorhergehenden Zeile:
define_direction (UP,‚oben‘ Wenn Python eines Syntaxfehlers beschwert, es hilft in der Regel vor der Linie auf der Linie zu sehen es beschwert sich tatsächlich über „
Dank wim, ich dachte nicht, über die Linie zu schauen, ich bin neu in der Codierung von Python. Danke, 5h1ne22 – 5h1ne22