自学Python笔记 Day 11: Lesson 30 ~ Lesson 32

Day 11

Lesson 30

上节课学了if语句 这节课新加了elif (else if)和else 举个例子

if a > b:
	print("a is bigger than b")
elif a < b:
	print("a is smaller than b")
else:
	print("a is equal to b")

假设a=2 b=10 他会一个一个下来判断 直到满足条件 输出

people = 35
chairs = 15
recliner = 40

if chairs > people:
    print("We should use chairs")
elif chairs < people:
    print("We should not use chairs")
else:
    print("Hmm... We can't decide either...")

if recliner > chairs:
    print("That's too much recliner!")
elif chairs < recliner:
    print("Yeah we should take the recliners")
else:
    print("We still can't decide...")

if people > recliner:
    print("Alright just take the recliners!")
else:
    print("Fine we'll not use anything then.")

Lesson 31

这个就是上一个if else的运用 可以自己设计一个~

sign = '>'
print("You are in a room with two doors, which door do you want to pick? 1 or 2?")
door1 = input(sign)

if door1 == "1":
    print("You are facing a chocolate cake, what do you want to do?")
    print("1. Eat all")
    print("2. Take a look and walk away")
    print("3. Take a little bit")
    cake = input(sign)
    if cake == "1":
        print("It's poison! You're dead.")
    elif cake == "2":
        print("You're safe.")
    else:
        print("You felt sick...")

else:
    print("You are facing a glass of juice, what do you want to do?")
    print("1. Drink all")
    print("2. Take a look and walk away")
    print("3. Drink a little bit")
    drink = input(sign)
    if drink == "1":
        print("It's too hot! You're dead.")
    elif drink == "2":
        print("You're safe")
    else:
        print("It's really hot, you're throat is hurt...")

Lesson 32

这课就是设置一个list 放进去内容 然后用for循环打印出来

junk_food = ['chips', 'ice-cream', 'chocolate']

for food in junk_food:
    print("I got %s" %food)

empty = []
for i in range(0,6):
    print("Adding %d in the list" %i)

好啦 今天的三课结束啦
Au revoir~

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值