python输入数字1-12,输出月份简写
时间: 2024-10-07 21:05:04 浏览: 48
Python编程基础题(7-输入星期数字,输出对应英文)
在Python中,你可以编写一个简单的函数来将用户输入的1到12之间的数字转换成对应的月份简写。这里是一个示例:
```python
def number_to_month(month_number):
month_dict = {
1: 'Jan', # January
2: 'Feb', # February
3: 'Mar', # March
4: 'Apr', # April
5: 'May', # May
6: 'Jun', # June
7: 'Jul', # July
8: 'Aug', # August
9: 'Sep', # September
10: 'Oct', # October
11: 'Nov', # November
12: 'Dec' # December
}
return month_dict.get(month_number, "Invalid input")
# 获取用户输入并转换
month_input = int(input("请输入1到12的数字代表月份:"))
print(number_to_month(month_input))
阅读全文