用pyhon使用列表实现输入一个月份,输出该月份对应的英文单词
时间: 2024-10-09 12:10:28 浏览: 36
rbm _RBM代码_researchwyi_rbm代码思路_rbm_pyhon_
在Python中,你可以创建一个字典来存储每个月份及其对应的英文名称,然后通过用户输入获取月份并从字典中查找对应值。以下是一个简单的例子:
```python
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"
}
def get_month_in_english():
month_input = int(input("请输入月份(1-12):"))
if month_input in months:
return months[month_input]
else:
return "无效的月份!"
# 获取用户输入并输出结果
month_word = get_month_in_english()
print(f"月份 {month_word} 对应的英文单词是 '{month_word}'.")
阅读全文