Python Dictionary Challenge Project Step 10

I’m stuck on the last question of the project because I can’t seem to get around the few instances of ‘Damages not recorded’ for the 10th problem in:

Below is my code but I can’t seem to figure out how to correct it so I’m not getting the ‘int’ object is not subscriptable error. I’ve tried to assign the string to an int, continue through or assign None but nothing seems to work. Pretty lost on the solution.

damage_scale = {0: 0, 1: 100000000, 2: 1000000000, 3: 10000000000, 4: 50000000000} def cane_damage_scale(hurricane_names, damage_scale): for cane in hurricane_names: hurricanes_by_damage = {0:[],1:[],2:[],3:[],4:[],5:[]} if hurricane_names[cane]['Damage'] == 'Damages not recorded': hurricane_names[cane]['Damage'] = 0 if hurricane_names[cane]['Damage'] == 0: hurricanes_by_damage[0].append(hurricanes_names[cane]['Damage']) elif hurricane_names[cane]['Damage'] > damage_scale[0] and hurricane_names[cane]['Damage'] <= damage_scale[1]: hurricanes_by_damage[1].append(hurricane_names[cane]['Damage']) elif hurricane_names[cane]['Damage'] > damage_scale[1] and hurricane_names[cane]['Damage'] <= damage_scale[2]: hurricanes_by_damage[2].append(hurricane_names[cane]['Damage']) elif hurricane_names[cane]['Damage'] > damage_scale[2] and hurricane_names[cane]['Damage'] <= damage_scale[3]: hurricanes_by_damage[3].append(hurricane_names[cane]['Damage']) else: hurricanes_by_damage[4].append(hurricane_names[cane]['Damage']) return hurricanes_by_damage hurricane_damage_scale = cane_damage_scale(damage_scale, hurricane_names)

Hey there, and welcome to the forums!! :slight_smile:

As the error says an int object is not subscriptable, I recommend throwing a print() in there to see what values you are working with. Based on how you’ve supplied your arguments, they might not be what you expect.

Specifically hurricane_names[cane].

Also, this is assuming you have hurricane_names defined somewhere in your program.

1 Like

I’ve tried adding in print() statements to try to problem solve, I even copied the solution code and corrected for the function titles I had used. Still getting errors " ‘>’ not supported between instances of ‘str’ and ‘int’ ". I am totally in the weeds for how to solve my code.

That error suggests there’s an attempted comparison with the > operator between a string type and an int type. For example the following throws an error:

error = "test" > 3

You’ll want to check your code for these comparison operators and make sure you are not comparing a string with an integer, Python’s tracebacks are very good at pinpointing the line where the error occurred.

If you can’t see where a string and int were compared then @8-bit-gaming’s suggestion of using print will help here just in case your data is not the type you expected. Print it out and find out for sure. The type() function may also be helpful for this.

1 Like