def get_rainfall():
a=input("type city name")
total=[]
while a!="":
b=input("type rainfall in m")
total.append({a:b})
if b!="":
a=input("type city name")
print(total)
for i in total:
for j, k in i:
print(f"{j}:{k}")
get_rainfall()
返回是:
type city namel
type rainfall in m5
type city namek
type rainfall in m6
type city name
[{'l': '5'}, {'k': '6'}]
Traceback (most recent call last):
line 15, in <module>
get_rainfall()
line 12, in get_rainfall
for j, k in i:
ValueError: not enough values to unpack (expected 2, got 1)
很奇怪啊,明明列表打印没问题,为什么取有问题?哪里出错了?