如何在某个输入之后结束if-else语句



好的,所以基本上我是在做一个选择你自己的冒险故事,每次我运行代码时,无论你选择哪一个选择,程序都会自动调出故事的下一部分,我该如何制作它,以便在你死后或故事中的其他事情结束。

story=print("又到夏天了。你去你姑妈家,他带你游览城市\他带你去城里最著名的建筑。他告诉你那栋楼闹鬼,但\你不相信他。")

choice_1=输入("你是进去还是留下来?")如果choice_1=="进入内部":print("你决定进去,你的姑姑说"小心"你开始走上老鬼屋的石阶\你打开门,走进来,突然一支利箭划过你的脸!但它想念你。")

choice_2 = input("Do you go up the staircase, into the kitchen, or do you run away?")
if choice_2 == "up the staircase":
    print (" You compose yourself, and go up the staircase. as you begin to reach the top, the floor beneath you breaks open

然后你就摔死了")elif choice_2=="走进厨房":打印("你镇定下来,决定穿过厨房。厨房里到处都是蛛网,没有其他有趣的东西。")elif choice_2=="逃跑":印刷品("你决定不去鬼屋和你阿姨一起吃冰淇淋。")其他:打印("无效输入")

choice_3 = input("you see two doors in front of you one is labeled "1" the other is labeled "2",

你选哪扇门?输入1或2")如果choice_3=="1":print("你打开左边的门,走进去。一阵风把你推出窗外\然后你掉进了灌木丛中。你吓得魂不附体,遇到了你的阿姨,然后开车去拿冰淇淋")elif choice_3=="2":print("你继续走进右边的门,房间后面有一口奇怪的棺材\棺材打开,一个吸血鬼跳了出来。你的大脑一片空白,在家里安全地躺在床上醒来\你的阿姨带你去吃冰淇淋,说"你可以想吃多少勺就吃多少勺")

choice_4 = int(input("How many scoops do you get?"))
if choice_4 < 4 and choice_4 > 0:
    print ("you enjoy your ice cream, forget about what happened, and never go into another abandoned house again")
elif choice_4 == 0:
    print ("you decide that you do not like ice cream anymore, and you try to forget about what happened,

但你慢慢地从你所经历的事情中变得疯狂")其他:打印("你吃了太多冰淇淋就吐了")

elif choice_1==("停留"):印刷品("你决定不去鬼屋和你阿姨一起吃冰淇淋。")其他:打印("无效输入")

有几种方法可以创建这种行为。一种方法是在导致"死亡"的选择之后添加一个return语句以退出一个函数:

    def story():
        choice_1 = input("choice")
        if choice_1 in ["choices","that","don't","end","in","death"]:
            print "you live and keep playing"
        else:
            return 0
        choice_2 = input("choose again")
        if choice_2 in ["choices","that","don't","end","in","death"]:
            print "you live and keep playing"
        else:
            return 0
    def the_end():
        print "you're dead"
story()
the_end()

最新更新