#练习 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 =20if 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:passelse: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:#也许能更进一步了