-
-
Save codecademydev/9dc1fb0a57602e07b900cecd0709f80d 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] | |
# 2 | |
# Update Recorded Damages | |
conversion = {"M": 1000000, | |
"B": 1000000000} | |
def updated_damages(dmg_list): | |
updated_list = [] | |
for ele in dmg_list: | |
if ele == 'Damages not recorded': | |
updated_list.append(ele) | |
elif ele[-1] == "M": | |
new_ele = float(ele[:-1]) * conversion.get("M") | |
updated_list.append(new_ele) | |
else: | |
new_ele = float(ele[:-1]) * conversion.get("B") | |
updated_list.append(new_ele) | |
#print(updated_list) | |
return updated_list | |
# test function by updating damages | |
updated_damage = updated_damages(damages) | |
#3 | |
# Create and view the hurricanes dictionary | |
def dict_hurricanes(name_lst, month_lst, year_lst, wind_lst, area_lst, damage_lst, death_lst): | |
hurricanes = {} | |
for i in range(0, len(name_lst)): | |
hurricanes[name_lst[i]] = {"Name": name_lst[i], "Month": month_lst[i], "Year": year_lst[i],"Max Sustained Wind": wind_lst[i],"Areas Affected": area_lst[i],"Damage": damage_lst[i],"Deaths": death_lst[i]} | |
return hurricanes | |
#Call hurricanes dictionary sorted by name | |
hurricanes_dict = dict_hurricanes(names, months, years, max_sustained_winds, areas_affected,updated_damage, deaths) | |
#print(hurricanes_dict) | |
# 4 | |
# Organizing by Year | |
def dict_hurricanes_year(year): | |
hurricane_by_year = [] | |
for name in hurricanes_dict: | |
if hurricanes_dict[name]['Year'] == year: | |
hurricane_by_year.append(hurricanes_dict[name]) | |
#print(hurricane_by_year) | |
return hurricane_by_year | |
#print(dict_hurricanes_year(2018)) | |
#print(dict_hurricanes_year(1932)) | |
#print(dict_hurricanes_year(1955)) | |
# 5 | |
# Counting Damaged Areas | |
affected_areas = {} | |
def count_affected_areas(dictionary): | |
for name in dictionary: | |
for area in dictionary[name]['Areas Affected']: | |
if area in affected_areas: | |
affected_areas[area] += 1 | |
else: | |
affected_areas[area] = 1 | |
return affected_areas | |
# create dictionary of areas to store the number of hurricanes involved in | |
hurricanes_area_count = count_affected_areas(hurricanes_dict) | |
#print(hurricanes_area_count) | |
# 6 | |
# Calculating Maximum Hurricane Count | |
def calculate_max_hurricane_count(affected_area_dict): | |
max_count = 0 | |
for key, value in affected_area_dict.items(): | |
if value > max_count: | |
max_count = value | |
max_area = key | |
return "{0} has the highest hurricane count with {1}".format(max_area, str(max_count)) | |
# find most frequently affected area and the number of hurricanes involved in | |
print(calculate_max_hurricane_count(hurricanes_area_count)) | |
# 7 | |
# Calculating the Deadliest Hurricane | |
def greatest_number_of_deaths(dictionary): | |
max_mortality = 0 | |
for name, value in dictionary.items(): | |
if max_mortality < value['Deaths']: | |
max_mortality_cane = name | |
max_mortality = value['Deaths'] | |
return "Hurricane {0} had the highest mortality rate with {1} deaths.".format(max_mortality_cane, str(max_mortality)) | |
# find highest mortality hurricane and the number of deaths | |
print(greatest_number_of_deaths(hurricanes_dict)) | |
# 8 | |
# Rating Hurricanes by Mortality | |
def hurricane_categarised_by_mortality_rate(dictionary): | |
mortality_scale = {0: 0, | |
1: 100, | |
2: 500, | |
3: 1000, | |
4: 10000} | |
hurricanes_by_mortality = {0:[],1:[],2:[],3:[],4:[]} | |
for name, value in dictionary.items(): | |
if value['Deaths'] > 0 and value['Deaths'] <= 100: | |
hurricanes_by_mortality[0].append(value) | |
elif value['Deaths'] > 100 and value['Deaths'] <= 500: | |
hurricanes_by_mortality[1].append(value) | |
elif value['Deaths'] > 500 and value['Deaths'] <=1000: | |
hurricanes_by_mortality[2].append(value) | |
elif value['Deaths'] > 1000 and value['Deaths'] <=10000: | |
hurricanes_by_mortality[3].append(value) | |
elif value['Deaths'] > 10000: | |
hurricanes_by_mortality[4].append(value) | |
return hurricanes_by_mortality | |
# categorize hurricanes in new dictionary with mortality severity as key | |
#print(hurricane_categarised_by_mortality_rate(hurricanes_dict)) | |
# 9 Calculating Hurricane Maximum Damage | |
def greatest_damage(dictionary): | |
max_damage_cane = '' | |
max_damage = 0 | |
for name, value in dictionary.items(): | |
if value['Damage'] == 'Damages not recorded': | |
pass | |
elif max_damage < int(value['Damage']): | |
max_damage = value['Damage'] | |
max_damage_cane = name | |
return "{0} Caused the most damage in monetary terms costing ${1} USD.".format(max_damage_cane, str(max_damage)) | |
# find highest damage inducing hurricane and its total cost | |
print(greatest_damage(hurricanes_dict)) | |
# 10 | |
# Rating Hurricanes by Damage | |
def hurricane_categarised_by_damage_cost(dictionary): | |
damage_scale = {0: 0, | |
1: 100000000, | |
2: 1000000000, | |
3: 10000000000, | |
4: 50000000000} | |
hurricanes_by_damage = {0:[],1:[],2:[],3:[],4:[]} | |
for name, value in dictionary.items(): | |
if value['Damage'] == 'Damages not recorded': | |
pass | |
elif value['Damage'] > 0 and value['Damage'] <= 100000000: | |
hurricanes_by_damage[0].append(value) | |
elif value['Damage'] > 100000000 and value['Damage'] <= 1000000000: | |
hurricanes_by_damage[1].append(value) | |
elif value['Damage'] > 1000000000 and value['Damage'] <=1000: | |
hurricanes_by_damage[2].append(value) | |
elif value['Damage'] > 10000000000 and value['Damage'] <=50000000000: | |
hurricanes_by_damage[3].append(value) | |
elif value['Damage'] > 50000000000: | |
hurricanes_by_damage[4].append(value) | |
return hurricanes_by_damage | |
# categorize hurricanes in new dictionary with damage severity as key | |
#print(hurricane_categarised_by_damage_cost(hurricanes_dict)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment