Help building a function

I want to build a function that calculates the difference between estimated insurance costs and actual insurance costs. I’m not quite sure how to get the data into the function and then store it to a list:

def insurance_cost_difference(estimated_insurance_data, insurance_data): cost_diff = estimated_insurance_data - insurance_data print("The difference in cost is: " + cost_diff) insurance_cost_difference = [] insurance_cost_difference.append(("Maria", maria_insurance_cost)) insurance_cost_difference.append(("Rohan", rohan_insurance_cost)) insurance_cost_difference.append(("Valentina", valentina_insurance_cost))

This is part 12 of the Python List Medical Insurance Project

1 - make sure that all variables are declared
2- cost_diff should be a string inside the print statement since python allow string concatenation only with string type, you can do this by type casting (str(cost_diff)).


By and large functions are designed to return something. On occasion they’ll serve the purpose of printing information and there’s nothing wrong with that, but in this example by returning the value of interest you can append them to a list and you can still print them by printing the call instead which makes your function much more useful.

1 Like