输入一个数字,返回对应季节用python写
时间: 2024-10-10 19:10:20 浏览: 26
Python 实现一行输入多个数字(用空格隔开)
5星 · 资源好评率100%
你可以编写一个简单的Python函数,根据输入的月份来确定对应的季节。这里有一个示例:
```python
def get_season(month):
seasons = {
1: "冬季", # January and February (北半球)
2: "冬季", # March
3: "春季", # April
4: "春季", # May
5: "夏季", # June
6: "夏季", # July
7: "夏季", # August
8: "秋季", # September
9: "秋季", # October
10: "秋季", # November
11: "冬季", # December (南半球)
12: "冬季" # In some systems, December in the Northern Hemisphere is also considered winter
}
return seasons.get(month, "未知")
# 测试函数
month = int(input("请输入月份(1-12): "))
season = get_season(month)
print(f"{month}月对应的季节是: {season}")
阅读全文