Skip to content

Instantly share code, notes, and snippets.

@codecademydev
Created February 6, 2021 01:52
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save codecademydev/155ec0139e93b29ffbf9a7f9bca72a80 to your computer and use it in GitHub Desktop.
Save codecademydev/155ec0139e93b29ffbf9a7f9bca72a80 to your computer and use it in GitHub Desktop.
Codecademy export
# 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]
# 1
# Update Recorded Damages
conversion = {"M": 1000000,
"B": 1000000000}
def update_damages(lst):
update_lst = []
for element in lst:
if element[-1] == 'M':
element = element.strip('M')
element = float(element) * 1000000
elif element[-1] == 'B':
element = element.strip('B')
element = float(element) * 1000000000
else:
element = "Damages not recorded"
update_lst.append(element)
return update_lst
# test function by updating damages
damage = update_damages(damages)
#print(damage)
# 2
# Create a Table
def contain_all(name, month, year, max_wind, area_affect, damage, death):
hurricanes = {}
for i in range(len(name)):
hurricanes[name[i]] = {'Name':name[i], 'Month':month[i], 'Year':year[i], 'Max Sustained Wind':max_wind[i], 'Areas Affected':area_affect[i], 'Damage':damage[i], 'Deaths':death[i]}
return hurricanes
# Create and view the hurricanes dictionary
hurricanes_dictionary = contain_all(names, months, years, max_sustained_winds, areas_affected, damage, deaths)
#print(hurricanes_dictionary)
# 3
# Organizing by Year
def order_by_year():
year_dict = {}
for year in years:
year_dict[year] = [x for x in hurricanes_dictionary.values() if x["Year"] == year]
return year_dict
# create a new dictionary of hurricanes with year and key
current_year = order_by_year()
#print(current_year)
# 4
# Counting Damaged Areas
def count_area():
count = {}
for area in areas_affected:
for loc in area:
if count.get(loc) is None:
count[loc] = 1
else:
count[loc] += 1
return count
# create dictionary of areas to store the number of hurricanes involved in
area_affect_count = count_area()
print(area_affect_count)
# 5
# Calculating Maximum Hurricane Count
def max_hurricane_count(areas):
max_area = ""
max_count = 0
for area, hit in areas.items():
if hit > max_count:
max_area = area
max_count = hit
return max_area, max_count
# find most frequently affected area and the number of hurricanes involved in
print(max_hurricane_count(area_affect_count))
# 6
# Calculating the Deadliest Hurricane
def severe():
severe_hurricane = ""
total_death = 0
for i in hurricanes_dictionary.values():
if i.get("Deaths") >= total_death:
severe_hurricane = i.get("Name")
total_death = i.get("Deaths")
return severe_hurricane, total_death
# find highest mortality hurricane and the number of deaths
print(severe())
# 7
# Rating Hurricanes by Mortality
def rate_mortality(hurricane):
hurricanes_by_mortality = {0:[],1:[],2:[],3:[],4:[], 5:[]}
for i in hurricane:
if hurricane[i]['Deaths'] >= 10000:
hurricanes_by_mortality[5].append(i)
elif 10000 > hurricane[i]['Deaths'] >=1000:
hurricanes_by_mortality[4].append(i)
elif 1000 > hurricane[i]['Deaths'] >=500:
hurricanes_by_mortality[3].append(i)
elif 500 > hurricane[i]['Deaths'] >=100:
hurricanes_by_mortality[2].append(i)
elif 100 > hurricane[i]['Deaths'] >0:
hurricanes_by_mortality[1].append(i)
else:
hurricanes_by_mortality[0].append(i)
return hurricanes_by_mortality
# categorize hurricanes in new dictionary with mortality severity as key
print(rate_mortality(hurricanes_dictionary))
# 8 Calculating Hurricane Maximum Damage
def max_damage_hur(hurr):
max_damage_hurr = ""
max_damage = 0
for hur in hurr:
if hurr[hur]['Damage'] == "Damages not recorded":
continue
if hurr[hur]["Damage"] > max_damage:
max_damage_hurr = hurr[hur]["Name"]
max_damage = hurr[hur]["Damage"]
return max_damage_hurr, max_damage
# find highest damage inducing hurricane and its total cost
print(max_damage_hur(hurricanes_dictionary))
# 9
# Rating Hurricanes by Damage
damage_scale = {0: 0,
1: 100000000,
2: 1000000000,
3: 10000000000,
4: 50000000000}
def damage_rate(hurr):
hurr_rate = {0:[],1:[],2:[],3:[],4:[], 5:[]}
for x,y in hurr.items():
if y["Damage"] == "Damages not recorded":
continue
else:
if y['Damage'] == 0:
hurr_rate[0].append(x)
if 0 < y['Damage'] <= 100000000:
hurr_rate[1].append(x)
if 100000000 < y['Damage'] <= 1000000000:
hurr_rate[2].append(x)
if 1000000000 < y['Damage'] <= 10000000000:
hurr_rate[3].append(x)
if 10000000000 < y['Damage'] <= 50000000000:
hurr_rate[4].append(x)
if y['Damage'] > 50000000000:
hurr_rate[5].append(x)
return hurr_rate
# categorize hurricanes in new dictionary with damage severity as key
print(damage_rate(hurricanes_dictionary))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment