修正
时间: 2023-07-31 17:05:32 浏览: 85
下面是修正后的代码:
```
jingmao = {'honest': '熊子豪', 'level': '3'}
puppy = {'honest': '钱政旭', 'level': '6'}
dubing = {'honest': '邓伟峰', 'level': '2'}
zangao = {'honest': '许文强', 'level': '1'}
pet = []
pet.append(jingmao)
pet.append(puppy)
pet.append(dubing)
pet.append(zangao)
for i in pet:
print(f'Honest is {i["honest"]}. Level is {i["level"]}')
```
这段代码创建了一个包含四个字典的列表 pet,每个字典都包含两个键值对,分别是'honest'和'level',表示宠物的诚实程度和等级。然后使用循环遍历 pet 列表中的每个字典,打印出每个宠物的'honest'和'level'值。输出结果如下:
```
Honest is 熊子豪. Level is 3
Honest is 钱政旭. Level is 6
Honest is 邓伟峰. Level is 2
Honest is 许文强. Level is 1
```
阅读全文