# alien_color = 'yellow'
alien_color = 'green'if alien_color == 'green':
print("You shoot a green alien and got 5 points")
5-4 外星人颜色#2
# alien_color == "green"
alien_color = "yellow"if alien_color == "green":
print("You shoot a green alien and got 5 points")
else:
print("Your shoot a strange alien and got 10 points")
5-5 外星人颜色#3
# alien_color = "green"# alien_color = "red"
alien_color = "yellow"if alien_color == "green":
print("You shoot a green alien and got 5 points")
elif alien_color == "yellow":
print("You shoot a yellow alien and got 10 points")
else:
print("You shoot a red alien and got 15 points")
5-6 人生的不同阶段
age = 19if age < 2:
print("You are a baby")
elif age < 4:
print("You are learning walking")
elif age < 13:
print("You are a child")
elif age < 20:
print("You are a teenager")
elif age < 65:
print("You are an adult")
else:
print("You are an elder")
5-7 喜欢的水果
favorite_fruits ={"apple", "banana", "pear"}
fruits = ["apple", "pear", "cherry", "banana", "pineapple"]
for fruit in fruits:
if fruit in favorite_fruits:
print("You really like " + fruit + "!")
5-8 以特殊方式跟管理员打招呼
users = ["Bob", "Alice", "Jack", "Eric", "admin"]
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 = ["Bob", "Alice", "Jack", "Eric", "admin"]
if 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")
else:
print("We need to find some users!")
while users:
users.pop()
if 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")
else:
print("We need to find some users!")
5-10 检查用户名
current_users = ["yamato", "fubuki", "agaki", "shimakaze", "saratoga"]
new_users = ["Poi", "Ark Royal", "Warspite", "Fubuki", "Saratoga"]
for user in new_users:
if user.lower() in current_users:
print("User name '" + user + "'used, please try again!")
else:
print("User name '" + user + "' available.")