程序码如下:
[In]
kids=20
snack=100
soda=21
candy= 25
if candy>kids: #如果糖果大於小孩则打印
print('Kids will get diabetes')
if soda>kids: #如果苏打水大於小孩则打印
print("There have 21 soda")
if kids != snack: #如果小孩人数不等於点心则打印
print('They save!')
[Out]
Kids will get diabetes
There have 21 soda
They save!
kids=10
snack=5
soda=8
candy= 3
if candy>kids: #如果糖果多於小孩就打印
print('Kids will get diabetes')
elif candy<kids: #反之
print("Kids are save")
else: #如果都没有达到上述条件则打印
print('Kids dont know how to do that!')
if soda>kids:
print("There have 8 soda")
elif soda<kids:
print("The soda is not enough")
else:
print('Soda is good')
if kids != snack: #不等於
print('They save!')
if kids >= 10: #检查左操作数的值是否大於或等於右操作数的值,如果是,则条件成立。
print("Too many kids")
[Out]
Kids are save
The soda is not enough
They save!
Too many kids
今日总结:
应该这样解释大家就对if else elif有着初步的认识了!
<<: 【左京淳的JAVA WEB学习笔记】第二章 Servlet
>>: CMoney第八届菁英软件工程师战斗营_Week 3
前面讲了那麽多,当然在部属unRaid还是要优先考虑设备的选择 当然用淘汰的旧电脑也是可以(小雨这次...
这个 30 天我们理解了 C 语言与 Objective-C,然而我其实有不少事情是没有看懂的,铁人...
前一篇我们谈到了事件系结的方法,在使用 事件系结(Event binding) 的时候,我们要先有一...
缺乏计画的目标,只能叫做愿望。 A goal without a plan is just a wi...
前面我们持续带入新的服务利用架构的方式解决网站负载问题,在资安方面使用了应用防火墙(WAF)能有效...