Hurricanes analysis step 5

Hello everyone I am Francesco and I got stuck with the last part (5) where I am asked to count how often each area is affected by hurricanes.
When I print my solution it only gives me the count for the first hurricane so I believe that my code is iterating only 1 hurricane and not through all of them.
Thanks for help

update_damages =
for x in damages:
if x == “Damages not recorded”:
update_damages.append(x)
if x[-1] == “M”:
update_damages.append(float(x[:-1])*conversion[“M”])
if x[-1] == “B”:
update_damages.append(float(x[:-1])*conversion[“B”])

print(len(names))
hurricanes = {}
def create_dictionary(names,months, years, max_sustained_winds, areas_affected, update_damages, deaths):
for x in range(len(names)):
hurricanes[names] = {“Name”: names,“Month”: months,“Year”: years,“Max Sustained Wind”: max_sustained_winds,“Areas Affected”:areas_affected,“Damage”: update_damages,“Deaths”: deaths}
return hurricanes

print(create_dictionary(names,months, years, max_sustained_winds, areas_affected, update_damages, deaths))

def hurricane_by_year(hurricanes):
hurricane_year = {}
for cane in hurricanes:
current_year = hurricanes[cane][‘Year’]
current_cane = hurricanes[cane]
if current_year not in hurricane_year:
hurricane_year[current_year] = [current_cane]
else:
hurricane_year[current_year].append(current_cane)
return hurricane_year

def affected_areas(hurricanes):
hurricane_areas = {}
for cane in hurricanes:
for area in hurricanes[cane][“Areas Affected”]:
if area not in hurricane_areas:
hurricane_areas[area] = 1
else:
hurricane_areas[area] += 1
return hurricane_areas

hurricane_areas = affected_areas(hurricanes)
print(hurricane_areas)

Without the indentation this is very hard to read, could you perhaps edit or reply to your post with fully formatted code (python without indentation is scary) and ideally a link to your project (what is step 5?). The following FAQ covers how to do this, ta.

This topic was automatically closed 41 days after the last reply. New replies are no longer allowed.