创建字典类型变量,存储一下信息: "1月":"梅花","2月":"杏花","3月":"桃花","4月":"牡丹花","5月":"石榴花","6月":"莲花","7月":"玉簪花","8月":"桂花","9月":"菊花","10月":"芙蓉花","11月":"山茶花","12月":"水仙花" 程序可以接受输入一个表示月份的整数(1—12),输出该月份对应的花名(取自上述字典)
时间: 2023-06-28 09:11:34 浏览: 41
python变量 数据类型 列表 元组 字典
```python
flowers = {"1月":"梅花","2月":"杏花","3月":"桃花","4月":"牡丹花","5月":"石榴花","6月":"莲花","7月":"玉簪花","8月":"桂花","9月":"菊花","10月":"芙蓉花","11月":"山茶花","12月":"水仙花"}
month = int(input("请输入月份(1-12): "))
if month in range(1,13):
print("{}月对应的花名是{}".format(month, flowers[str(month)+"月"]))
else:
print("请输入正确的月份!")
```
运行结果:
```
请输入月份(1-12): 3
3月对应的花名是桃花
```
阅读全文