第 36 行的语法错误
Syntax Error on line 36
我的基于文本的冒险的第 36 行总是出现语法错误。
我在行末添加了 #line 36
以告诉您它在哪里。
我已经尝试了我能想到的一切来解决这个问题。我错过了什么?
#Adventure
#Setting
print ("*You wake up in a dark room on a mattress that is on the floor*")
#Wait before running next command to make it seem more real and more like a real thought.
import time
time.sleep(1)
#Introduce the Map
print ("*You look to your left and there is a wall, you then look to your right and find a short table with a map on it*")
import time
time.sleep(1)
print("*You pick up the map*")
map = """
|---------------------|
| |
| Start |
| |
| |
|---------------------|"""
print (map)
def goto(linenum):
global line
line = linenum
line = 1
while True:
if line == 1:
response = raw_input("Would you like to explore around the room or move to next the room? (Type explore ,or move-on): ")
if response == "explore":
map = """
|---------------------|---------------------|
| | |
| Start | Room 2 |
| | |
| | |
|---------------------|---------------------|"""
print (map)
elif response = "move-on": #line 36
map = """
|-------------------------------------------|
| |
| [Chest] |
| D |
| O |
| O |
| (table) R |
| {Bed} |
|-------------------------------------------|"""
print (map)
else:
goto(100)
break
elif line == 100:
print "Your input is invalid"
goto(1)
您不需要多次导入模块(即,开始时只 import time
一次)。
话虽如此,您打印语句:
print (map)
缩进错误(两次都被称为[第 35 行和第 47 行])
可能还有其他问题,但这是您的代码目前正在处理的问题。
将 elif response = "move-on": #line 36
更改为 elif response == "move-on": #line 36
。你忘了等号
我的基于文本的冒险的第 36 行总是出现语法错误。
我在行末添加了 #line 36
以告诉您它在哪里。
我已经尝试了我能想到的一切来解决这个问题。我错过了什么?
#Adventure
#Setting
print ("*You wake up in a dark room on a mattress that is on the floor*")
#Wait before running next command to make it seem more real and more like a real thought.
import time
time.sleep(1)
#Introduce the Map
print ("*You look to your left and there is a wall, you then look to your right and find a short table with a map on it*")
import time
time.sleep(1)
print("*You pick up the map*")
map = """
|---------------------|
| |
| Start |
| |
| |
|---------------------|"""
print (map)
def goto(linenum):
global line
line = linenum
line = 1
while True:
if line == 1:
response = raw_input("Would you like to explore around the room or move to next the room? (Type explore ,or move-on): ")
if response == "explore":
map = """
|---------------------|---------------------|
| | |
| Start | Room 2 |
| | |
| | |
|---------------------|---------------------|"""
print (map)
elif response = "move-on": #line 36
map = """
|-------------------------------------------|
| |
| [Chest] |
| D |
| O |
| O |
| (table) R |
| {Bed} |
|-------------------------------------------|"""
print (map)
else:
goto(100)
break
elif line == 100:
print "Your input is invalid"
goto(1)
您不需要多次导入模块(即,开始时只 import time
一次)。
话虽如此,您打印语句:
print (map)
缩进错误(两次都被称为[第 35 行和第 47 行])
可能还有其他问题,但这是您的代码目前正在处理的问题。
将 elif response = "move-on": #line 36
更改为 elif response == "move-on": #line 36
。你忘了等号