import time
print("hello, do you want to play this detective game?")
choice == input( "Yes or no?")
if choice 'no' :
print: "ok then, bye"
exit
if choice'yes':
start
name == input("Enter your name")
print("hello, " + name ", in this game you are a famous detective handling a theft case."
time.sleep(1)
print(" you have gone on a holiday but ended up lost in the forest. you see a man walking up to you")
time.sleep(1)
print ("man:' hi there! you seem quite lost! Do you want to stay the night with me?'")
print(" you said:'why should i? i dont even know you'")
print(" man : ' Do as you please, but if you stay in the forest for the night here's a friendly warning: there's wild wolves in the forests.'")
choose == input( "stay the night or refuse?" )
if choose "refuse":
print("man: ' boy, you are stubborn!")
print( "the man walks away, leaving you behind" + " In the end, you got eaten by the wolves due to your stubborness. THE END")
choice == input("do you want to play again? yes or no?")
if choice "yes":
start
if choice "no":
print( "ok then, bye!")
exit
基本上我的问题是这个'语法无效'在鞋帮[你想玩吗? ]'不'响应。
但当我删除它时问题会转到下一行。这很烦人,我找不到如何解决它。
我尝试在'之间进行切换。和"但结果仍然相同。
如果你们中的任何一个人在我昨天刚刚开始的时候花时间回应并且仍然不清楚无效语法,我会很高兴。
答案 0 :(得分:0)
if choice 'no' :
是罪魁祸首(在第8行和其他地方也是如此)。该表达式需要==
来生成:
if choice == 'no' :
但是,第3行在到达之前会导致问题 - 未定义choice
。 ==
是一个逻辑运算符,它并不意味着赋值,因为代码似乎需要在那时进行。更改它以使用=
执行作业:
choice = input( "Yes or no?")
此外,最好针对小写进行测试,因为您不知道用户可能输入的大写和小写字符的组合:
if choice.lower() == 'no' :
第9行再次阅读start
。也许你的意思是作为评论?如果是这样,请在行的开头添加'#'
。
这些问题是冰山一角。也许你应该以小的迭代增量阅读一些教程和代码来构建你的程序。
答案 1 :(得分:0)
试试这个:
import time
def game()
print("hello, do you want to play this detective game?")
choice == input( "Yes or no?")
if choice == 'no' :
print("ok then, bye")
break
if choice == 'yes':
name == input("Enter your name")
print("hello, " + name ", in this game you are a famous detective handling a theft case."
time.sleep(1)
print(" you have gone on a holiday but ended up lost in the forest. you see a man walking up to you")
time.sleep(1)
print ("man:' hi there! you seem quite lost! Do you want to stay the night with me?'")
print(" you said:'why should i? i dont even know you'")
print(" man : ' Do as you please, but if you stay in the forest for the night here's a friendly warning: there's wild wolves in the forests.'")
choose == input( "stay the night or refuse?" )
if choose == "refuse":
print("man: ' boy, you are stubborn!")
print( "the man walks away, leaving you behind" + " In the end, you got eaten by the wolves due to your stubborness. THE END")
choice == input("do you want to play again? yes or no?")
if choice == "yes":
game()
if choice == "no":
print("ok then, bye!")
break
else:
#continue your game here
希望这有效!这可能会更好。
答案 2 :(得分:0)
的问题:
choice == input()
错误,请choice = input()
choice 'no' :
在许多地方再次出错choice == 'no'
start
/ exit
不是必需的print()
函数必须具有右括号修正代码:
import time
def my_game():
print("hello, do you want to play this detective game?")
choice = input( "Yes or no?")
if choice == 'no' :
print("ok then, bye")
if choice == 'yes':
name = input("Enter your name")
print("hello, " + name + ", in this game you are a famous detective handling a theft case.")
time.sleep(1)
print(" you have gone on a holiday but ended up lost in the forest. you see a man walking up to you")
time.sleep(1)
print ("man:' hi there! you seem quite lost! Do you want to stay the night with me?'")
print(" you said:'why should i? i dont even know you'")
print(" man : ' Do as you please, but if you stay in the forest for the night here's a friendly warning: there's wild wolves in the forests.'")
choose = input( "stay the night or refuse?" )
if choose == "refuse":
print("man: ' boy, you are stubborn!")
print( "the man walks away, leaving you behind" + " In the end, you got eaten by the wolves due to your stubborness. THE END")
choice = input("do you want to play again? yes or no?")
if choice == "yes":
my_game()
if choice == "no":
print( "ok then, bye!")
if __name__ == "__main__":
my_game()