Hurricane Analysis Challenge Project (Python)

I see it now, line 64 is where the user set the value of the current key to a list with [current_cane]. I tested that out as well and it makes sense to me. Thank you for the help!

This is my code after completing the project. That was good practice!

Hello, here is my code. Feel free to comment!

Here’s my hurricane project, found much more simple way in the solution!
Any feedback would be appreciated, thanks :smiley:

This project was great! I learned a lot from completing it and felt much more confident by the end. Would love some feedback from anyone if you’d like.

Hello, everyone, I recently got started with the Data Science path and I just finished this project. I wanted to do with as little help as possible, just the knowledge I’ve learned so far. Now my code works, and I know people here can tell me right away how and what to refactor, which ill take right now, BUT I wanted to know where I can learn what to look for. I want to be able to refactor and clean code on my own. So any articles or courses(maybe that I haven’t gotten to yet) would be great. Thank you!

Finally finished my very first Codecademy project!
Any feedback is appreciated, thanks you all!
Happy coding!

Finished my Hurricane analysis challenge. Here’s my code, I hope it’s helpful (and right?!)

names of hurricanes

names = [‘Cuba I’, ‘San Felipe II Okeechobee’, ‘Bahamas’, ‘Cuba II’, ‘CubaBrownsville’, ‘Tampico’, ‘Labor Day’, ‘New England’, ‘Carol’, ‘Janet’, ‘Carla’, ‘Hattie’, ‘Beulah’, ‘Camille’, ‘Edith’, ‘Anita’, ‘David’, ‘Allen’, ‘Gilbert’, ‘Hugo’, ‘Andrew’, ‘Mitch’, ‘Isabel’, ‘Ivan’, ‘Emily’, ‘Katrina’, ‘Rita’, ‘Wilma’, ‘Dean’, ‘Felix’, ‘Matthew’, ‘Irma’, ‘Maria’, ‘Michael’]

months of hurricanes

months = [‘October’, ‘September’, ‘September’, ‘November’, ‘August’, ‘September’, ‘September’, ‘September’, ‘September’, ‘September’, ‘September’, ‘October’, ‘September’, ‘August’, ‘September’, ‘September’, ‘August’, ‘August’, ‘September’, ‘September’, ‘August’, ‘October’, ‘September’, ‘September’, ‘July’, ‘August’, ‘September’, ‘October’, ‘August’, ‘September’, ‘October’, ‘September’, ‘September’, ‘October’]

years of hurricanes

years = [1924, 1928, 1932, 1932, 1933, 1933, 1935, 1938, 1953, 1955, 1961, 1961, 1967, 1969, 1971, 1977, 1979, 1980, 1988, 1989, 1992, 1998, 2003, 2004, 2005, 2005, 2005, 2005, 2007, 2007, 2016, 2017, 2017, 2018]

maximum sustained winds (mph) of hurricanes

max_sustained_winds = [165, 160, 160, 175, 160, 160, 185, 160, 160, 175, 175, 160, 160, 175, 160, 175, 175, 190, 185, 160, 175, 180, 165, 165, 160, 175, 180, 185, 175, 175, 165, 180, 175, 160]

areas affected by each hurricane

areas_affected = [[‘Central America’, ‘Mexico’, ‘Cuba’, ‘Florida’, ‘The Bahamas’], [‘Lesser Antilles’, ‘The Bahamas’, ‘United States East Coast’, ‘Atlantic Canada’], [‘The Bahamas’, ‘Northeastern United States’], [‘Lesser Antilles’, ‘Jamaica’, ‘Cayman Islands’, ‘Cuba’, ‘The Bahamas’, ‘Bermuda’], [‘The Bahamas’, ‘Cuba’, ‘Florida’, ‘Texas’, ‘Tamaulipas’], [‘Jamaica’, ‘Yucatn Peninsula’], [‘The Bahamas’, ‘Florida’, ‘Georgia’, ‘The Carolinas’, ‘Virginia’], [‘Southeastern United States’, ‘Northeastern United States’, ‘Southwestern Quebec’], [‘Bermuda’, ‘New England’, ‘Atlantic Canada’], [‘Lesser Antilles’, ‘Central America’], [‘Texas’, ‘Louisiana’, ‘Midwestern United States’], [‘Central America’], [‘The Caribbean’, ‘Mexico’, ‘Texas’], [‘Cuba’, ‘United States Gulf Coast’], [‘The Caribbean’, ‘Central America’, ‘Mexico’, ‘United States Gulf Coast’], [‘Mexico’], [‘The Caribbean’, ‘United States East coast’], [‘The Caribbean’, ‘Yucatn Peninsula’, ‘Mexico’, ‘South Texas’], [‘Jamaica’, ‘Venezuela’, ‘Central America’, ‘Hispaniola’, ‘Mexico’], [‘The Caribbean’, ‘United States East Coast’], [‘The Bahamas’, ‘Florida’, ‘United States Gulf Coast’], [‘Central America’, ‘Yucatn Peninsula’, ‘South Florida’], [‘Greater Antilles’, ‘Bahamas’, ‘Eastern United States’, ‘Ontario’], [‘The Caribbean’, ‘Venezuela’, ‘United States Gulf Coast’], [‘Windward Islands’, ‘Jamaica’, ‘Mexico’, ‘Texas’], [‘Bahamas’, ‘United States Gulf Coast’], [‘Cuba’, ‘United States Gulf Coast’], [‘Greater Antilles’, ‘Central America’, ‘Florida’], [‘The Caribbean’, ‘Central America’], [‘Nicaragua’, ‘Honduras’], [‘Antilles’, ‘Venezuela’, ‘Colombia’, ‘United States East Coast’, ‘Atlantic Canada’], [‘Cape Verde’, ‘The Caribbean’, ‘British Virgin Islands’, ‘U.S. Virgin Islands’, ‘Cuba’, ‘Florida’], [‘Lesser Antilles’, ‘Virgin Islands’, ‘Puerto Rico’, ‘Dominican Republic’, ‘Turks and Caicos Islands’], [‘Central America’, ‘United States Gulf Coast (especially Florida Panhandle)’]]

damages (USD($)) of hurricanes

damages = [‘Damages not recorded’, ‘100M’, ‘Damages not recorded’, ‘40M’, ‘27.9M’, ‘5M’, ‘Damages not recorded’, ‘306M’, ‘2M’, ‘65.8M’, ‘326M’, ‘60.3M’, ‘208M’, ‘1.42B’, ‘25.4M’, ‘Damages not recorded’, ‘1.54B’, ‘1.24B’, ‘7.1B’, ‘10B’, ‘26.5B’, ‘6.2B’, ‘5.37B’, ‘23.3B’, ‘1.01B’, ‘125B’, ‘12B’, ‘29.4B’, ‘1.76B’, ‘720M’, ‘15.1B’, ‘64.8B’, ‘91.6B’, ‘25.1B’]

deaths for each hurricane

deaths = [90,4000,16,3103,179,184,408,682,5,1023,43,319,688,259,37,11,2068,269,318,107,65,19325,51,124,17,1836,125,87,45,133,603,138,3057,74]

write your update damages function here:

conversion = {“M”: 1000000,
“B”: 1000000000}

updated_damage =

def convert_damages(damage):
for i in damage:
if i == ‘Damages not recorded’:
updated_damage.append(i)
elif conversion[i[-1:len(i)]] == 1000000:
new = float(i[0:len(i) - 1]) * 1000000
updated_damage.append(new)

    elif conversion[i[-1:len(i)]] == 1000000000:
        new1 = float(i[0:len(i) - 1]) * 1000000000
        updated_damage.append(new1)

return updated_damage

updated_damages = convert_damages(damages)

print(“Updated damages in float”)
print(updated_damages)
print("-----------------------------------------------------")

write your construct hurricane dictionary function here:

def create_dictionary(names, months, years, max_sustained_winds, areas_affected, updated_damages, deaths):

hurricanes = {}
num_hurricanes = len(names)

for i in range(num_hurricanes):
hurricanes[names[i]] = {“Name”: names[i],
“Month”: months[i],
“Year”: years[i],
“Max Sustained Wind”: max_sustained_winds[i],
“Areas Affected”: areas_affected[i],
“Damage”: updated_damages[i],
“Deaths”: deaths[i]}
return hurricanes

hurricanes = create_dictionary(names, months, years, max_sustained_winds, areas_affected, updated_damages, deaths)

print(“Hurricane dictionary”)
print(hurricanes)
print("-----------------------------------------------------")

write your construct hurricane by year dictionary function here:

def convert_by_years(dictionary):
years_dic = {}
for i in dictionary.values():
year = i.get(“Year”)
name = i.get(“Name”)
month = i.get(“Month”)
year = i.get(“Year”)
max_w = i.get(“Max Sustained Wind”)
area_a = i.get(“Areas Affected”)
damage = i.get(“Damage”)
deaths = i.get(“Deaths”)
years_dic.update({year: [name, month, year, max_w, area_a, damage, deaths]})
return years_dic

years_dictionary = convert_by_years(hurricanes)
print(“Hurrcane by Year Dictionary”)
print(years_dictionary)
print("-----------------------------------------------------")

write your count affected areas function here:

def count_canes_by_area(dictionary):
hurricanes_by_area = {}
for name in dictionary.values():
for area in name[‘Areas Affected’]:
if area in hurricanes_by_area:
hurricanes_by_area[area] += 1
else:
hurricanes_by_area[area] = 1
return hurricanes_by_area

hurricanes_by_area = count_canes_by_area(hurricanes)
print(“Affected Areas Count”)
print(hurricanes_by_area)
print("-----------------------------------------------------")

write your find most affected area function here:

def most_affected_area(dictionary):
max_area_counter = 0
max_area = ‘’
for name, area in hurricanes_by_area.items():
if area > max_area_counter:
max_area_counter = area
max_area = name
return max_area, max_area_counter

affected_area = most_affected_area(hurricanes)
print(“Most affected Area”)
print(affected_area)
print("-----------------------------------------------------")

write your greatest number of deaths function here:

def max_deaths(dictionary):
max_deaths_num = 0
max_deaths_cane = ‘’
for name in dictionary.values():
if name[‘Deaths’] >= max_deaths_num:
max_deaths_num = name[‘Deaths’]
max_deaths_cane = name[‘Name’]
return max_deaths_cane, max_deaths_num

max_cane_death = max_deaths(hurricanes)
print(“Hurrance with the most deaths”)
print(max_cane_death)
print("-----------------------------------------------------")

write your catgeorize by mortality function here:

mort_ratings = {
0: ,
1: ,
2: ,
3: ,
4: ,
5:
}
def mortality(dictionary):
for hurricane, data in dictionary.items():
current_cane = hurricane
num_deaths = data[‘Deaths’]
if num_deaths == 0:
mort_ratings[0].append(current_cane)
elif num_deaths > 0 and num_deaths <= 100:
mort_ratings[1].append(current_cane)
elif num_deaths > 101 and num_deaths <= 500:
mort_ratings[2].append(current_cane)
elif num_deaths > 501 and num_deaths <= 1000:
mort_ratings[3].append(current_cane)
elif num_deaths > 1000 and num_deaths <= 10000:
mort_ratings[4].append(current_cane)
else:
mort_ratings[5].append(current_cane)

mortality(hurricanes)
print(“MORTALITY RATINGS: " + str(mort_ratings))
print(”-----------------------------------------------------")

write your greatest damage function here:

def greatest_damage(dictionary):
mostcostlycane = {}
maxcane = 0
maxcanename = ‘’
for hurricanes, data in dictionary.items():
costlycane = data[‘Damage’]
if costlycane == ‘Damages not recorded’:
continue
if costlycane >= maxcane:
maxcane = costlycane
maxcanename = hurricanes

return(maxcane, maxcanename)

costlycane = greatest_damage(hurricanes)
print(“Most costly Hurricane” + str(costlycane))
print("-----------------------------------------------------")

write your catgeorize by damage function here:

damage_scale = {0: ,
1: ,
2: ,
3: ,
4: }

def dam_scale(dictionary):
for hurricane, data in dictionary.items():
current_cane = hurricane
damage_tot = data[‘Damage’]
if damage_tot == 0:
damage_scale[0].append(current_cane)
elif damage_tot > 0 and damage_tot <= 100000000:
damage_scale[1].append(current_cane)
elif damage_tot > 100000001 and damage_tot <= 1000000000:
damage_scale[2].append(current_cane)
elif damage_tot > 1000000001 and damage_tot <= 10000000000:
damage_scale[3].append(current_cane)
else:
damage_scale[4].append(current_cane)
return damage_scale

damage_dic = dam_scale(hurricanes)
print(“Hurricanes on a damage scale”)
print(damage_dic)
print("-----------------------------------------------------")

It was great practice! I enjoyed figuring out the most efficient way of coding. Feedbacks appreciated!

My code here. Happy to receive any feedback (it works, but I believe it could have been done in fewer liner for cleaner code)

very efficient imo, better than the sample solution!

dont give up if you really like it!! it really was difficult

Hi everyone,

Happy to be here to build some new skills. This was challenging but it looks like I made it.

Here is my code:

Thank you!

Hurricane Analysis

My solution for the hurricane project.

my hurricane project

Hy solution for the hurricane project:
Hurricane project