我是Python新手,不知道为什么这不起作用。我四处搜索,看到很多人都有这个问题,他们可以找到解决办法。如果你能解释为什么它不能帮助其他人,这将有所帮助。感谢
print ("Welcome to The Haunted Theme Park...")
print (" ")
print ("Your aim is to not get killed and find the HOLY SWORD.")
print (" ")
print ("Would you like to enter? 1)Enter the theme park. 2) Leave and go home.")
answer = int(input((""))
def yes():
print ("Welcome to the Haunted theme Park.")
print (" ")
print ("You slowly tip-toe in. In the distance you see a light.")
print ("Do you want to 1) Walk to the light. 2) Walk another way.")
if answer == "1":
choice = yes
elif answer == "2":
print ("You turn around and someone is behind you.")
print (" ")
print ("He stabs you in the throat and you slowly suffer a painful death...")
print (" ")
print ("THE END")
它表示def。
存在语法错误答案 0 :(得分:4)
好像是你的
answer = int(input((""))
行缺少右括号!或者可能有一个括号太多。
此外,正如Ciaran Liedeman补充的那样,你的第一个“打印”行有一个缩进问题(为什么会有多个缩进?)。
最后,我相信你希望当答案为“是”时调用“是”函数,所以你的代码可能是:
print ("Welcome to The Haunted Theme Park...")
print ("")
print ("Your aim is to not get killed and find the HOLY SWORD.")
print ("")
print ("Would you like to enter? 1)Enter the theme park. 2) Leave and go home.")
answer = int(input(""))
def yes():
print ("Welcome to the Haunted theme Park.")
print ("")
print ("You slowly tip-toe in. In the distance you see a light.")
print ("Do you want to 1) Walk to the light. 2) Walk another way.")
if answer == 1:
yes()
elif answer == 2:
print ("You turn around and someone is behind you.")
print ("")
print ("He stabs you in the throat and you slowly suffer a painful death...")
print ("")
print ("THE END")
答案 1 :(得分:1)
您的代码存在很多问题。您的函数调用格式不正确,并且input()
后面没有结束括号。
看看以下布局:
def yes():
print ("Welcome to the Haunted theme Park.")
print (" ")
print ("You slowly tip-toe in. In the distance you see a light.")
print ("Do you want to 1) Walk to the light. 2) Walk another way.")
print ("Welcome to The Haunted Theme Park...")
print (" ")
print ("Your aim is to not get killed and find the HOLY SWORD.")
print (" ")
print ("Would you like to enter? 1)Enter the theme park. 2) Leave and go home.")
answer = int(input(""))
if answer == 1:
choice = yes()
elif answer == 2:
print ("You turn around and someone is behind you.")
print (" ")
print ("He stabs you in the throat and you slowly suffer a painful death...")
print (" ")
print ("THE END")
您还将输入转换为数字,但您的if
语句将其与字符串值进行比较。