繁体   English   中英

我的 if else 输入循环不起作用,我不知道为什么

[英]My if else loop for an input doesn't work and I don't know why

choice_five = (input("(1) fire ball  (2) cast cloak  "))

if choice_five == "1":
    print("you start up your fire ball and nod at Draco. you both start to advance down the path.")
    print("you turn the corner and stare face to face with two cloaked figures. they react with out hesitation.")
    print("one of the cloaks throws a dark orb of energy at Draco. he swings his axe at it, but it has no effect.")
    print("Draco flys backwards and slams into a tree. you throw your fire ball at the cloak, bu twhen it nears he seems to absorb it.")
    print("a second to late you see the second orb flying at you. you sucumb to the tearing pain and die.")

    restart_one = (input("would you like to try that again? "))

    if restart_one == "yes":
        choice_five
    else:
        print("then stay dead.")

我的重新启动命令工作正常,但它不会运行第二个问题五...我可以得到一些帮助。

您可以通过while循环达到您的目标。 while循环在您的情况下迭代循环。 我还在嵌套的if循环之后添加了pass语句,这样如果你的答案等于yes ,它就会通过并再次转到第一行:

while True:
    choice_five = (input("(1) fire ball  (2) cast cloak  "))
    if choice_five == "1":
        print("you start up your fire ball and nod at Draco. you both start to advance down the path.")
        print("you turn the corner and stare face to face with two cloaked figures. they react with out hesitation.")
        print("one of the cloaks throws a dark orb of energy at Draco. he swings his axe at it, but it has no effect.")
        print("Draco flys backwards and slams into a tree. you throw your fire ball at the cloak, bu twhen it nears he seems to absorb it.")
        print("a second to late you see the second orb flying at you. you sucumb to the tearing pain and die.")

        restart_one = (input("would you like to try that again? "))

        if restart_one == "yes":
            pass
        else:
            print("then stay dead.")
            break

玩得开心 :)

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM