5-1
animal = 'tiger'
print("Is animal == tiger? I predict Ture.")
print(animal == "tiger")
print("\nIs animal == lion? I predict False")
print(animal == "lion")
输出结果:
Is animal == tiger? I predict Ture.
True
Is animal == lion? I predict False
False
5-5
color = "green"
if color == "green":
print("you get 5 points.")
elif color == "yellow":
print("you get 10 points.")
else:
print("you get 15 points.")
color = "yellow"
if color == "green":
print("you get 5 points.")
elif color == "yellow":
print("you get 10 points.")
else:
print("you get 15 points.")
color = "red"
if color == "green":
print("you get 5 points.")
elif color == "yellow":
print("you get 10 points.")
else:
print("you get 15 points.")
输出结果:
you get 5 points.you get 10 points.
you get 15 points.
5-7
favorite_fruits = ['apple','banana','watermelon']
if 'apple' in favorite_fruits:
print("you really like apple.")
if 'pineapple' in favorite_fruits:
print("you really like pineapple.")
if 'banana' in favorite_fruits:
print("you really like banana.")
if 'watermelon' in favorite_fruits:
print("you really like watermelon.")
if 'pear' in favorite_fruits:
print("you really like pear.")
输出结果:
you really like apple.
you really like banana.
you really like watermelon.
5-10
current_users = ['admin','Kangkang','Mike','Jake','Quinlan']
new_users = ['Kangkang','Helen','MIKE','Faker','Uzi']
current_users_upper = []
for user in current_users:
current_users_upper.append(user.upper())
for user in new_users:
if user.upper() in current_users_upper:
print(user + " is used,please enter another name!")
else:
print(user + " can be used.")
输出结果:
Kangkang is used,please enter another name!
Helen can be used.
MIKE is used,please enter another name!
Faker can be used.
Uzi can be used.