【发布时间】:2020-06-23 20:14:47
【问题描述】:
我知道如何执行 if 语句和 elif 语句,但在此特定代码中我不知道如何执行。我试图做的是当用户放置女性或男性和温度时,它将根据选择的性别显示适合该天气的服装。谁能帮帮我?
def main():
print("Welcome to Outfitters Boulevard!")
print()
print("Where your next vacation outfit is just around the corner.")
print("================================================")
name = input("What is your name?")
gender = input("Are you male or female?")
favoriteColor = input("What is your favorite color?")
temp = int(input("What is the temperature like where you're going?"))
print(name + ", you mentioned that you're a female, your favorite color is " + favoriteColor + ",")
print("and you're going somewhere with " + str(temp) + " weather.")
print("We've got just the outfit for you: ")
if temp>84:
print("The Perfect Hot Weather Outfit")
elif 70 >=temp<= 84:
print("The Perfect Warm Weather Outfit")
elif 55>=temp<= 69:
print("The Perfect Cool Weather Outfit")
elif temp <55:
print("The Perfect Cold Weather Outfit")
main()
【问题讨论】:
-
会显示哪种服装适合哪种性别?
-
对于“完美的炎热天气服装”,如果用户是女性,它将显示短裤、凉鞋、太阳帽和短款衬衫,但如果用户是男性,它将显示夏威夷衬衫、短裤和人字拖
-
您的比较语法错误。应该是
elif 70 <= temp <= 84: -
另请注意,在带有“您提到您是女性”的打印语句中,您应该使用从输入中获得的
gender变量 -
@anonymous123 我已经使用您提供的示例回答了您的问题。
标签: python if-statement