years = int(input("How many years?: "))
i= 0
temperaturer = {}
monthnumber = 1
nummer = 1
while i <= years:
print("Which is " + str(nummer) + ":a year?: ")
for i in range(0,13):
temp = input("Month " + str(monthnumber) + ": ")
monthnumber += 1
if monthnumber == 13:
break
temperaturer.append(temp)
是否有一种简单的方法可以让这种情况重复多次,如#34;顶部多少年?&#34;
答案 0 :(得分:0)
years = int(input("How many years?: "))
numeral = {1 : 'first', 2: 'second'} # and so on
data = {}
for year in range(1, years + 1):
cur_year = input("Which is the " + numeral[year] + " year?: ")
data[cur_year] = {}
for month in range(1, 13):
d = input("Month " + str(month) + ": ")
data[cur_year][month] = d
print data
{2012: {1: 22,
2: 1,
3: 42,
4: 22,
5: 3,
6: 22,
7: 11,
8: 23,
9: 42,
10: 1,
11: 223,
12: 23},
2018: {1: 23,
2: 2,
3: 4,
4: 1,
5: 52,
6: 235,
7: 2,
8: 52,
9: 25,
10: 25,
11: 25,
12: 25}