Dec-17-2017, 09:50 PM
for city, pollutin in data.items():Spelling!
avg[city]= sum(pollution)/float(len(pollution))how far is avg indented? and why float(len(pollution))? when k show how many time a city appears.
def number_of_polluted_days(januar): k = {} for day, data in januar.items(): for city, pollution in data.items(): d = ['Texas', 'Moscow', 'Berlin', 'Athens'] if city not in k: k[city]=0 if city in k: k[city] += 1 #a code to sum a pollution with respect to city print(k) #Shows the number of time a city appears. #the average should be calculated here #avg[city]= sum(pollution)/float(len(pollution)) return k januar = { 1: {'Texas': 126, 'Moscow': 64, 'Berlin': 57, 'Athens': 35,}, 2: {'Texas': 53, 'Moscow': 56, 'Berlin': 58,}, 3: {'Texas': 34, 'Moscow': 71, 'Berlin': 48, 'Athens': 55,} } number_of_polluted_days(januar)
When my code doesn't work I don't know why **think** and when my code works I don't know why **think**