用Python使用列表编写一个程序,用户输入 一个月份,程序就输出对应月份的英文单词
时间: 2024-09-25 13:02:55 浏览: 49
Python 实现一行输入多个数字(用空格隔开)
5星 · 资源好评率100%
当然可以,这里是一个简单的Python程序,它会提示用户输入月份,然后返回对应的英文单词表示:
```python
def month_to_english():
months = {
"1": "January",
"2": "February",
"3": "March",
"4": "April",
"5": "May",
"6": "June",
"7": "July",
"8": "August",
"9": "September",
"10": "October",
"11": "November",
"12": "December"
}
user_input = input("请输入月份(1-12): ")
if user_input.isdigit() and int(user_input) in range(1, 13):
return months.get(str(user_input), "Invalid month")
else:
return "Please enter a number between 1 and 12."
month_str = month_to_english()
print(f"The English word for the month is: {month_str}")
#
阅读全文