Python的If条件判断练习

练习题来自于《Python编程:从入门到实践》
#5.1假设在游戏中刚射杀了一个外星人,请创建一个名为alien_color的变量,并将其设置
#为'green'、'yellow'或'red'
aline_color=('green','yellow','red')
if 'green' in aline_color:
        print('Get 5 point')
if 'yellow' not in aline_color:
        print(null)
#5.2编写一个if-else结构
for aline in aline_color:
    if aline=='green':
        print('Get 5 point')
    else:
        print('Get 10 point')
#5.3 if-else结构改为if-elif-else结构
for aline in aline_color:
    if aline=='green':
        print('get 5 point')
    elif aline =='yellow':
        print('get 10 point')
    else:
        print('get 15 point')
#5.4 设置变量age的值,再编写一个ifelif-else结构,根据age的值判断处于人生的哪个阶段。
age=25
if age<2:
    print('you are a baby')
elif age>=2 and age<4:
    print('you are studying limp')
elif age>=4 and age<13:
    print('you are a child')
elif age>=13 and age<20:
    print('you are a teenager')
elif age>=20 and age<65:
    print('you are a adult')
else:
    print('you are a older')
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值