设计一个程序,根据用户输入的月份输出对应的季节
时间: 2024-09-19 08:18:08 浏览: 42
设计这样一个程序并不复杂,通常我们可以使用if...else if...else结构来判断输入的月份,并关联相应的季节。这里是一个简单的Python示例:
```python
def get_season(month):
seasons = {
1: "冬季", # January and February
2: "冬季", # February
3: "春季", # March
4: "春季", # April
5: "夏季", # May
6: "夏季", # June
7: "夏季", # July
8: "秋季", # August
9: "秋季", # September
10: "秋季", # October
11: "冬季", # November
12: "冬季" # December
}
if month in seasons:
return seasons[month]
else:
return "请输入正确的月份"
# 用户输入
month_input = int(input("请输入月份 (1-12): "))
season = get_season(month_input)
print(f"{month_input}月对应的季节是: {season}")
阅读全文