Hurricane Project help

I’m having a problem with the first part of the project. I misread the prompt to start and just thought I needed to update the damages list. The code that I used for that works exactly as intended.

updated_list = [] for i in damages: if 'M' in i: new = i.split('M') updated_list.append(float(new[0])*1000000) elif 'B' in i: new2 = i.split('B') updated_list.append(float(new2[0])*1000000000) else: updated_list.append(i) print(updated_list)

However, when I went back and tried to write it inside the function, all of a sudden the code does not return the same result. I only get a list with a single item. Can someone please explain what is going on? I could try to do this another way, but I want to understand why the code works as a for loop but fails as a for loop inside a function.

def update_list(assignment_list): updated_list = [] for i in assignment_list: if 'M' in i: new = i.split('M') updated_list.append(float(new[0])*1000000) elif 'B' in i: new2 = i.split('B') updated_list.append(float(new2[0])*1000000000) else: updated_list.append(i) return updated_list update_list(damages)

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

Be careful with the usage of the return statement in a function. When it executes it evaluates the expression to the right and returns that value to the caller exiting the function at that point.

Thank you so much! Fixing that worked.

1 Like

I notice you’re not using the provided lookup table, conversion. Any reason why?