-
-
Save codecademydev/b0d3f9aac093e4e58b43d1b0b92d9d2b to your computer and use it in GitHub Desktop.
Codecademy export
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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: | |
def hurricanes_damage (damages_recorded): | |
updated_damages = [] | |
for damage in damages_recorded: | |
if damage == "Damages not recorded": | |
updated_damages.append(damage) | |
elif damage[-1] == "M": | |
value = float(damage[:-1]) *1000000 | |
updated_damages.append(value) | |
elif damage[-1] == "B": | |
value = float(damage[:-1]) * 1000000000 | |
updated_damages.append(value) | |
return updated_damages | |
damages_updated = hurricanes_damage(damages) | |
#print(damages_updated) | |
# write your construct hurricane dictionary function here: | |
def hurricane_dictionary (name, month, year, max_wind, areas, damage, death): | |
h_dict = {} | |
for i in range(len(name)): | |
h_dict[name[i]] = {} | |
h_dict[name[i]].update({"Name":name[i]}) | |
h_dict[name[i]].update({"Month":month[i]}) | |
h_dict[name[i]].update({"Year":year[i]}) | |
h_dict[name[i]].update({"Max Sustained Wind":max_wind[i]}) | |
h_dict[name[i]].update({"Areas Affected":areas[i]}) | |
h_dict[name[i]].update({"Damage":damage[i]}) | |
h_dict[name[i]].update({"Deaths":death[i]}) | |
return h_dict | |
hurricane_dict = hurricane_dictionary(names, months, years, max_sustained_winds, areas_affected, damages_updated, deaths) | |
# print (hurricane_dict) | |
# write your construct hurricane by year dictionary function here: | |
def hurricane_by_year (hurricane_dictionary): | |
h_by_year = {} | |
for year in years: | |
hurricanes = [] | |
for hurricane in hurricane_dictionary.values(): | |
if hurricane['Year'] == year: | |
hurricanes.append(hurricane) | |
h_by_year[year] = hurricanes | |
return h_by_year | |
hurricane_year = hurricane_by_year(hurricane_dict) | |
#print (hurricane_year) | |
# write your count affected areas function here: | |
def count_areas (affected_areas): | |
affected_area_count = {} | |
for area in affected_areas: | |
for location in area: | |
if affected_area_count.get(location) is None: | |
affected_area_count[location] = 1 | |
else: | |
affected_area_count[location] += 1 | |
return affected_area_count | |
areas_affected_count = count_areas(areas_affected) | |
# print (areas_affected_count) | |
# write your find most affected area function here: | |
def most_affected_area (areas): | |
place = "" | |
max_hits = 0 | |
for area,hits in areas.items(): | |
if hits > max_hits: | |
place = area | |
max_hits = hits | |
return place, max_hits | |
area, hits = most_affected_area(areas_affected_count) | |
#print("Most affected area is:{area} with {hits} hits".format(area = area, hits = hits)) | |
# write your greatest number of deaths function here: | |
def greatest_deaths (hurricane_dictionary): | |
hurricane_name = "" | |
total_deaths = 0 | |
for hurricane in hurricane_dictionary.values(): | |
if hurricane.get("Deaths") > total_deaths: | |
hurricane_name = hurricane.get("Name") | |
total_deaths = hurricane.get("Deaths") | |
return hurricane_name, total_deaths | |
hurricane, deaths = greatest_deaths(hurricane_dict) | |
# print("The greatest number of deaths is:{deaths} from hurricane {hurricane}".format(deaths = deaths, hurricane = hurricane)) | |
# write your catgeorize by mortality function here: | |
def categorize_by_mortality (hurricane_dictionary): | |
hurricane_by_mortality = {0:[], 1:[], 2:[], 3:[], 4:[]} | |
for hurricane in hurricane_dictionary.values(): | |
deaths = hurricane.get("Deaths") | |
if deaths >= 0 and deaths < 100: | |
hurricane_by_mortality[0].append(hurricane.get("Name")) | |
elif deaths >=100 and deaths < 500: | |
hurricane_by_mortality[1].append(hurricane.get("Name")) | |
elif deaths >=500 and deaths < 1000: | |
hurricane_by_mortality[2].append(hurricane.get("Name")) | |
elif deaths >=1000 and deaths < 10000: | |
hurricane_by_mortality[3].append(hurricane.get("Name")) | |
else: | |
hurricane_by_mortality[4].append(hurricane.get("Name")) | |
return hurricane_by_mortality | |
hurricane = categorize_by_mortality (hurricane_dict) | |
""" | |
for category, name_list in hurricane.items(): | |
print("Category {category}: {hurricanes}".format(category = category, hurricanes = name_list)) | |
""" | |
# write your greatest damage function here: | |
def greatest_damage (hurricane_dictionary): | |
hurricane_name = "" | |
total_damage = 0 | |
for hurricane in hurricane_dictionary.values(): | |
damage = hurricane.get("Damage") | |
if damage == "Damages not recorded": | |
continue | |
elif damage > total_damage: | |
hurricane_name = hurricane.get("Name") | |
total_damage = damage | |
return hurricane_name, total_damage | |
hurricane, damage = greatest_damage(hurricane_dict) | |
print("The greatest damage is for: ${damage} from hurricane {hurricane}".format(damage = damage, hurricane = hurricane)) | |
# write your catgeorize by damage function here: | |
def categorize_by_damage (hurricane_dictionary): | |
hurricane_by_damage = {0:[], 1:[], 2:[], 3:[], 4:[]} | |
for hurricane in hurricane_dictionary.values(): | |
damage = hurricane.get("Damage") | |
if damage == "Damages not recorded": | |
continue | |
elif damage >= 0 and damage < 100000000: | |
hurricane_by_damage[0].append(hurricane.get("Name")) | |
elif damage >=100000000 and damage < 1000000000: | |
hurricane_by_damage[1].append(hurricane.get("Name")) | |
elif damage >=1000000000 and damage < 10000000000: | |
hurricane_by_damage[2].append(hurricane.get("Name")) | |
elif damage >=10000000000 and damage < 50000000000: | |
hurricane_by_damage[3].append(hurricane.get("Name")) | |
else: | |
hurricane_by_damage[4].append(hurricane.get("Name")) | |
return hurricane_by_damage | |
hurricane = categorize_by_damage (hurricane_dict) | |
for category, name_list in hurricane.items(): | |
print("Category {category}: {hurricanes}".format(category = category, hurricanes = name_list)) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment