Hurricane analysis Part 8 issue with datatypes and comparison

Hi!
I’m doing the Hurricane Analysis Project as part of the Data Science foundations and I am finding it pretty tricky. Have managed to get to Step 8. “Write a function that finds the hurricane that caused the greatest damage, and how costly it was.”
This is my code:

# Calculating Hurricane Maximum Damage
def max_damages(hurricane_dictionary):
    max_damage = 0
    hurricane_name = ""
    for hurricane in hurricane_dictionary:
        if hurricane_dictionary[hurricane]['Damage'] == 'Damages not recorded': 
            continue
        elif hurricane_dictionary[hurricane]['Damage'] > max_damage: 
            max_damage = hurricane_dictionary[hurricane]['Damage'], 
            hurricane_name = hurricane
    return hurricane_name, max_damage
            
# find highest damage inducing hurricane and its total cost
print(max_damages(hurricane_dictionary))

I get the error: “TypeError: ‘>’ not supported between instances of ‘float’ and ‘tuple’” for the elif line.
I’ve checked the data types in the dictionary by replacing the elif function and they all return as float.

Thanks in advance.

You can’t compare a float and a tuple, so, some of the values you have stored must be in a tuple. Did you use the .zip() function at any point in your code? That would create a tuple.

Is there a solution file for this project? (I seem to recall there was). Maybe take a look at that and see if it sheds any light?

Thanks for the reply. I had a look at the solution file and it’s pretty much identical except uses “pass” instead of “continue”. I just don’t see how there is a tuple when all the data types (except the not recorded ones) are reported as floats…

There’s a stray comma there in the elif…unless that’s meant to be there(?)…which I’m thinking it’s not supposed to be there & is a typo.

From the docs:
“A special problem is the construction of tuples containing 0 or 1 items: the syntax has some extra quirks to accommodate these. Empty tuples are constructed by an empty pair of parentheses; a tuple with one item is constructed by following a value with a comma (it is not sufficient to enclose a single value in parentheses). Ugly, but effective…”

Which is why you might be getting that error message.

Docs here.

1 Like

That’s it!
Removed the comma and it works. Thank you!

1 Like