Python基础练习题(外星人颜色、人生的不同阶段、喜欢的水果)
5-3
代码:
getplayer=input(“请输入颜色为green、yellow和red的外星人中的一个:”)
alien_color=“green”
if getplayer==alien_color:
print(“恭喜你获得5个点”)
运行结果:
5-4
代码:
getplayer=input(“请输入颜色为green、yellow和red的外星人中的一个:”)
alien_color=“green”
if getplayer==alien_color:
print(“恭喜你获得5个点”)
else:
print(“恭喜你获得10个点”)
运行结果:
5-5
代码:
getplayer=input(“请输入颜色为green、yellow和red的外星人中的一个:”)
if getplayer==“green”:
print(“恭喜你获得5个点”)
elif getplayer==“yellow”:
print(“恭喜你获得10个点”)
else:
print(“恭喜你获得15个点”)
运行结果:
5-6
代码:
getage=input(“请输入年龄:”)
age=int(getage)
if 0<age<2:
print(“你是婴儿”)
elif age<4:
print(“你正蹒跚学步”)
elif age<13:
print(“你是儿童”)
elif age<20:
print(“你是青少年”)
elif age<65:
print(“你是成年人”)
else:
print(“你是老年人”)
运行结果:
5-7
代码:
favorite_fruits = [“apples”, “oranges”, “bananas”]
if “apples” in favorite_fruits:
print(“I really like apples!”)
if “oranges” in favorite_fruits:
print(“I really like oranges!”)
if “pears” in favorite_fruits:
print(“I really like pears!”)
if “lemons” in favorite_fruits:
print(“I really like lemons!”)
if “bananas” in favorite_fruits:
print(“I really like bananas!”)
运行结果: