Skip to content

Instantly share code, notes, and snippets.

@rng009
Created May 30, 2020 15:50
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 rng009/ad546660400293ffc38370cccfbfc2bd to your computer and use it in GitHub Desktop.
Save rng009/ad546660400293ffc38370cccfbfc2bd to your computer and use it in GitHub Desktop.
The following code is to test my abilities in completing the Codecademy's Hurricane Analysis project
# 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:
upd_damages = []
for item in damages:
if item == 'Damages not recorded':
upd_damages.append(item)
if item[-1] == 'M':
upd_damages.append(float(item.replace('M', ''))*1000000)
if item[-1] == 'B':
upd_damages.append(float(item.replace('B', ''))*1000000000)
#print(upd_damages)
# write your construct hurricane dictionary function here:
def hur_stats(hur_name):
for item in names:
if item == hur_name:
index = names.index(item)
return ({'Name': names[index], 'Month': months[index], 'Year': years[index], 'Max Sustained Wind': max_sustained_winds[index], 'Areas Affected': areas_affected[index], 'Damage': upd_damages[index], 'Death' : deaths[index]})
#print(hur_stats('Cuba I'))
# write your construct hurricane by year dictionary function here:
def yr_info_call(year):
for item in years:
if item == year:
index = years.index(item)
count_of_year = years.count(item)
list_of_index = [index + i for i in range(count_of_year)]
list_of_yr_dic = [({'Name': names[c], 'Month': months[c], 'Year': years[c], 'Max Sustained Wind': max_sustained_winds[c], 'Areas Affected': areas_affected[c], 'Damage': upd_damages[c], 'Death' : deaths[c]}) for c in list_of_index]
return list_of_yr_dic
#print(yr_info_call(1931))
# write your count affected areas function here:
hur_dic = {'Name': names, 'Month': months, 'Year': years, 'Max Sustained Wind': max_sustained_winds, 'Areas Affected': areas_affected, 'Damage': upd_damages, 'Death' : deaths}
def affected_areas(hur_dictionary, l_key):
a_a_dic = {}
req_dic = {}
req_dic[l_key] = hur_dictionary[l_key]
for value in req_dic.values():
for item in value:
for strings in item:
if strings not in a_a_dic:
a_a_dic[strings] = 0
a_a_dic[strings] += 1
return a_a_dic
#print(affected_areas(hur_dic, 'Areas Affected'))
# write your find most affected area function here:
aff_area_dic = affected_areas(hur_dic, 'Areas Affected')
def most_freq_hit(my_dictionary):
new_dic = {}
max_area = 'Bahamas'
freq = 0
for key, value in my_dictionary.items():
if value > freq:
max_area = key
freq = value
new_dic[max_area] = freq
return new_dic
#print(most_freq_hit(aff_area_dic))
# write your greatest number of deaths function here:
def hur_of_death(hur_dic):
max_death = 0
death_hurricane = 'Name here'
death_stats = {}
death_stats['Deaths'] = hur_dic['Death']
for deaths in death_stats.values():
for death in deaths:
if death > max_death:
max_death = death
index = deaths.index(max_death)
hur_names = {}
hur_names['Names'] = hur_dic['Name']
for value in hur_names.values():
the_name = value[index]
death_hurricane = the_name
return death_hurricane, max_death
#print(hur_of_death(hur_dic))
# write your catgeorize by mortality function here:
def mortality_function(hur_dic):
mort_list = []
death_dic = {}
death_dic['Death'] = hur_dic['Death']
for value in death_dic.values():
for death in value:
if death > 0 and death < 100:
mort_list.append(1)
elif death >= 100 and death < 500:
mort_list.append(2)
elif death >= 500 and death <1000:
mort_list.append(3)
elif death >= 1000 and death < 10000:
mort_list.append(4)
elif death > 10000:
mort_list.append(5)
else: mort_list.append(0)
return mort_list
hur_dic['Mortality Rate'] = mortality_function(hur_dic)
#print(hur_dic)
# write your greatest damage function here:
def costliest_hur(hur_dic):
max_value = 0
lista = []
the_cane = 'I do not know, Katrina?'
the_dic = {}
lista = []
index = 0
the_dic['Damages'] = hur_dic['Damage']
for value in the_dic.values():
for damages in value:
lista.append(str(damages))
if damages != 'Damages not recorded':
if damages > max_value:
max_value = damages
indexa = lista.index(str(max_value))
new_dic = {}
new_dic['Names'] = hur_dic['Name']
for names in new_dic.values():
the_cane = names[indexa]
return the_cane, max_value
#print(costliest_hur(hur_dic))
# write your catgeorize by damage function here:
def damage_function(hur_dic):
damage_list = []
damage_dic = {}
damage_dic['Damages'] = hur_dic['Damage']
for value in damage_dic.values():
for damage in value:
if damage == 'Damages not recorded':
damage_list.append(0)
elif damage > 0 and damage < 100000000:
damage_list.append(1)
elif damage >= 100000000 and damage < 1000000000:
damage_list.append(2)
elif damage >= 1000000000 and damage <10000000000:
damage_list.append(3)
else: damage_list.append(4)
return damage_list
hur_dic['Damage Rating'] = damage_function(hur_dic)
print(hur_dic)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment