Hurricane Analysis step 9

Hello!
I am having trouble with the Hurricane Analysis project, step 9. This is my code:

damages_count = dict(zip(names, damages_new))
print(damages_count['Cuba I'])
def most_damages(damages_count):
  max_area = ""
  max_count = 0
  max_damages = {}
  for area in damages_count:
    if damages_count[area] == 'Damages not recorded':
      continue
    if damages_count[area] == max(damages_count.values()):
      max_area = area
      max_damages += damages_count[area]
      max_damages.update({max_area:max_damages})
    print(max_damages)
most_damages(damages_count)

When I run it I get TypeError: ‘>’ not supported between instances of ‘float’ and ‘str’.
I am not sure exactly why this happens. Any tips would be appreciated :slight_smile:

Here’s the link:
https://www.codecademy.com/paths/data-science/tracks/dscp-python-fundamentals/modules/dscp-python-dictionaries-challenge-projects/projects/hurricane-analysis

Hi welcome to the forums! :slight_smile:

Could you reformat the code in your post by deleting your code, pressing the Screen Shot 2020-12-28 at 3.54.18 PM button and pasting in-between the tick marks Screen Shot 2020-12-28 at 3.54.20 PM ? This will make the code more readable by users and someone can help you quicker/more accurately!

In terms of the error that usually happens when you try to compare a type string with a type float or int. Try converting your string to a float.

thanks for the tip! could you take a look at it now?

Yea even without knowing the dictionary values, these two sets of conditionals are in conflict:

if damages_count[area] == 'Damages not recorded'

and

if damages_count[area] == max(damages_count.values())

it’s similar to saying

if x == "some string" and x == someNum, but that would imply x is both a string and a number.

The issue is what is the type of the value stored in damages_count[area]. If for some reason you must have mixed types (strings/numbers/booleans/etc.), then you need to account for this. (you can always print out your dictionary beforehand to look at the its structure and values/types).

Probably in this case, since you’re not running any code block for the null values you could filter them out and iterate list instead.

If that’s not reasonable you could consider using try/except (not a huge fan of this as it’s a workaround in this particular case… I think).

thanks for your help!