《笨办法学python3-Learn Python 3 the HARD WAY》-习题31 做出决定

学习内容:

print ("""You enter a dark room with two doors.
Do you go through door #1 or door #2?""")

door = input("> ")

if door == "1":
    print ("There's a giant bear here eating a cheese cake.")
    print ("What do you do?")
    print ("1. Take the cake.")
    print ("2. Scream at the bear.")

    bear = input("> ")

    if bear == "1":
        print ("The bear eats your face off.  Good job!")
    elif bear == "2":
        print ("The bear eats your legs off.  Good job!")
    else:
        print (f"Well, doing {beat} is probably better.")
        print ("Bear runs away.")

elif door == "2":
    print ("You stare into the endless abyss at Cthulhu's retina.")
    print ("1. Blueberries.")
    print ("2. Yellow jacket clothespins.")
    print ("3. Understanding revolvers yelling melodies.")

    insanity = input("> ")

    if insanity == "1" or insanity == "2":
        print ("Your body survives powered by a mind of jello.")
        print ("Good job!")
    else:
        print ("The insanity rots your eyes into a pool of muck.")
        print ("Good job!")

else:
    print ("You stumble around and fall on a knife and die.  Good job!")

运行结果:
在这里插入图片描述
知识点:

  1. 本脚本流程
    在这里插入图片描述
  2. 写一个类似的脚本游戏
    又写了一个中文的,比较方便看和理解:
# --coding: utf-8 --
print ("森林里有两间小屋,左边的小屋是巧克力做的巧克力屋,右边小屋是蛋糕做的蛋糕屋。")
cabin = input("left or right > ")

if cabin == "left" or "l":
    print ("小屋里全是巧克力,还有两只小动物。一只小狗,一只小猫。")
    animal = input("cat or dog > ")
    if animal == "cat":
        print ("小猫慵懒的躺在火炉边,向你招招手。")

    elif animal == "dog":
        print ("小狗欢快的奔向你并冲你摇尾巴。")

    else:
        print ("你身后出现了一个女巫把你赶出了森林。")


elif cabin == "right" or "r":
    print ("小屋里的一切都是蛋糕做成的,里面有一个小姑娘看着你。")
    print ("你是上前和他打招呼还是站着不动?")
    behavior = input("1.打招呼 or 2.站着不动 > ")

    if behavior == "打招呼" or "1":
        print ("你向小姑娘打了招呼,小姑娘给你了一个杯子蛋糕。")
        print ("你是吃还是不吃呢?")
        eat = input("yes or no > ")
        if eat == "yes" or "y":
            print ("小姑娘是个女巫,你被施了咒语。以后只能留在蛋糕屋里,再也不能出去了。")
        elif eat == "no" or "n":
            print ("你拒绝了。瞬间小屋消失了,你现在在森林外面。")
        else:
            print ("你被扔出了小屋,再一次站在两个小屋前。")

    elif behavior == "站着不动" or "2":
        print ("小姑娘走到你的面前。一张嘴把你吞了进去。")

    else:
        print ("小姑娘变身为女巫,把你变成了小屋内的一款新蛋糕。")


else:
    print ("你越走越远,迷失在森林里。")
  1. 若是一个值在某个区域内的方式
    ①:1 < x <10 或者 1 <= x <10
    ②: x in range(1, 10)
    括号内的值可以理解为 1 <= x < 10,括号内的逗号左边的数值是包含在内的,右边的数值不包含在内,也就是x的取值范围是1~9。
    例:
# --coding: utf-8 --
girl = int(input("girl> "))
boy = int(input("boy> "))
teacher = int(input("teacher> "))

print ("""组织小朋友去春秋。
有两辆车,一辆大巴可以坐35个人,一辆中巴可以做20个人。
要根据人数订车。""")
people = girl + boy + teacher

if people in range(20, 35):
    print (f"孩子加上老师一共有{people}人。")
    print ("需要定一辆大巴。")
elif people in range(1, 20):
    print (f"孩子加上老师一共有{people}人。")
    print ("订一辆中巴就可以坐下所有人了")
elif people <= 0:
    print ("活动取消,不用订车了")
else:
    print (f"孩子加上老师一共有{people}人。")
    print ("一辆车不够,还要在根据人数多订几辆。")
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值