#5-3 外星人颜色
alien_color = "green"
if alien_color == "green":
score = "5"
print("YOU GOT " + score + " POINTS!")
alien_color = "red"
if alien_color == "green":
score = "5"
print("YOU GOT " + score + " POINTS!")
#5外星人颜色2
alien_color = "green"
if alien_color =="green":
score = "5"
print("YOU GOT " + score + " POINTS!")
else:
score = "10"
print("YOU GOT " + score + " POINTS!")
#5-5外星人颜色3
alien_color = "red"
if alien_color == "green":
socre="5"
print("YOU GOT " + score + " POINTS!")
elif alien_color == "yellow":
score="10"
print("YOU GOT " + score + " POINTS!")
else:
score="15"
print("YOU GOT "+ score +" POINTS!")
#5-6 人生的不同阶段
age = 20
if age < 2:
print("You are a baby!")
elif age>=2 and age<4:
print("You are a toddler!")
elif age >=4 and age<13:
print("You are a preteen!")
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 elderly!")
#5-7喜欢的水果
favorite_fruits = ["banana","apple","orange"]
if "banana" in favorite_fruits:
print("You really like banana!")
if "apple" in favorite_fruits:
print("You really like apple!")
if "orange" in favorite_fruits:
print("You really like orange!")
if "peach" in favorite_fruits:
print("You really like peach!")
if "lemon" in favorite_fruits:
print("You really like lemon!")
#5-8 以特殊方式跟管理员打招呼
users = ["admin","lucy","lily","xiaoming","xiaohong"]
for user in users:
if user == "admin":
print("Hello admin ,would you like to see a status report?")
else:
print("Hello " + user + " thank you for logging in again")
# 5-9处理没有用户的情形
users = ["admin","lucy","lily","xiaoming","xiaohong"]
del users[:]
for user in users:
if user == "admin":
print("Hello admin ,would you like to see a status report?")
else:
print("Hello " + user + " thank you for logging in again")
if len(users)==0:
print("We need to find some users!")
#5-10检查用户名
current_users =["xiaoming","xiaohong","xiaogang","xiaowang","xiaoyang"]
new_users = ["XIAOgang","xiaoHong","xiaowei","xiaoxiao","xiaoleng"]
for new_user in new_users:
if new_user.lower() in current_users:
print(new_user + " has registered,enter another one")
else:
print(new_user + " is available")
#5-11序数
a = range(1,10)
for i in a:
if i == 1:
print(str(i)+"st")
elif i == 2:
print(str(i)+"nd")
elif i == 3:
print(str(i)+"rd")
else:
print(str(i)+"th")









网友评论