第5章--if语句

#练习 5-1:
# ‘=’是赋值,‘==’是判断,返回True or False

#练习 5-2:
# I got it! so i don't need to do it.

#练习 5-3:
alien_color = 'green'
if alien_color == 'green':
    print('player,you got five points')
alien_color = 'red'
if alien_color == 'green':
    print('player,you got five points') 
       
#练习 5-4:
alien_color = 'green'
if alien_color == 'green':
    print('player,you got five points')
else:
    print('player,you got ten points')
alien_color = 'red'
if alien_color == 'green':
    print('player,you got five points')
else:
    print('player,you got ten points')   
     
#练习 5-5:
alien_color = 'green'
if alien_color == 'green':
    print('player,you got five points')
elif alien_color == 'yellow':
    print('player,you got ten points')
else:
    print('player,you got fifth points')    
alien_color = 'red'
if alien_color == 'green':
    print('player,you got five points')
elif alien_color == 'yellow':
    print('player,you got ten points')
else:
    print('player,you got fifth points')    
alien_color = 'yellow'
if alien_color == 'green':
    print('player,you got five points')
elif alien_color == 'yellow':
    print('player,you got ten points')
else:
    print('player,you got fifth points')
            
#练习 5-6:
age = 20
if age <2:
    print("This person is a baby")
elif age<4:
    print("This person is a Toddler")
elif age<13:
    print("This person is a child")
elif age<20:
    print("This person is a teenager")
elif age<65:
    print("This person is an adult")
else:
    print("This person is an old people")  
     
#练习 5-7:
favorite_fruits = ['桃子','芒果','葡萄','香蕉','橙子']
if '桃子' in favorite_fruits:
    print('you really like 桃子')
if '大蒜' in favorite_fruits:
    print('you really like 大蒜')
if '橙子' in favorite_fruits:
    print('you really like 橙子')
if '果冻' in favorite_fruits:
    print('you really like 果冻')
if '香蕉' in favorite_fruits:
    print('you really like 香蕉')    
    
#练习 5-8:
usernames = ['admin','bdmin','cdmin','ddmin','edmin']
for username in usernames:
    if username == 'admin':
        print(f'hello {username},would you like to see a status report?')
    else:
        print(f'hello {username},thank you for logging in again')    

#练习 5-9:
usernames = ['admin','bdmin','cdmin','ddmin','edmin']    
usernames.clear()
if usernames:
    pass
else:
    print('we need to find some users!')
     
#练习 5-10:
current_users = ['AdMin','bDmin','CdmIn','ddmiN','edmin','jdmin']
lower_current_users = [value.lower() for value in current_users[:]] 
new_users = ['admin','bdmin','fdmin','gdmin','hdmin']    
for user in new_users:
    if user.lower() in lower_current_users:
        #用户名不区分大小写
        print('You need to enter another username')
    else:
        print('This username is not used')
    
#练习 5-11:
digitals = list(range(1,10))
for digital in digitals:
    if digital <= 1 :
        print(f'{digital}st')
    elif digital <= 2 :
        print(f'{digital}nd')
    elif digital <= 3 :
        print(f'{digital}rd')
    else:
        print(f'{digital}th')
#练习 5-12:
# everything is right
#练习 5-13:
#也许能更进一步了 
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

-阿呆-

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值