# Python Functions: Medical Insurance Project (EXTRA: insurance cost difference)

Hi fellow coders. I have a question about the Extra assignment from Python functions/Medical Insurance Project (https://www.codecademy.com/paths/data-science/tracks/dscp-python-fundamentals/modules/dscp-python-functions/projects/ds-python-functions-project). As you can see in the code below, the estimations of Maria’s, Omar’s and my insurance cost are being printed onto the output window as they should, however, I do not understand why def calculate_costdifference does not print anything onto the output window. Where is the mistake I made? I am a beginner and I cannot find my mistake. I’d appreciate it if someone could help out.

# Create calculate_insurance_cost() function below:

def calculate_insurance_cost(name,age,sex,bmi,num_of_children,smoker):
estimated_cost = 250age - 128sex + 370bmi + 425num_of_children + 24000*smoker - 12500

return estimated_cost, print(“The estimated insurance cost for " + name + " is " + str(estimated_cost) + " dollars.”)

# Estimate Maria’s insurance cost

maria_insurance_cost = calculate_insurance_cost(name = “Maria”,age = 28, sex = 0, bmi = 26.2, num_of_children = 3, smoker = 0)

# Estimate Omar’s insurance cost

Omar_insurance_cost = calculate_insurance_cost(name = “Omar”,age = 35, sex = 1, bmi = 22.2, num_of_children = 0, smoker = 1)

#Estimate my insurance cost
my_insurance_cost =calculate_insurance_cost(name =“Me”, age = 27, sex = 0, bmi = 25.7, num_of_children = 0, smoker = 0)

def calculate_costdifference(my_insurance_cost, Omar_insurance_cost):
cost_difference = Omar_insurance_cost - my_insurance_cost
return cost_difference, print(“The difference in insurance cost is " + str(difference_insurance_cost) + " dollars”)

It’s quite difficult to read without formatting, could you please check the following FAQ which covers how to format code for the forums amongst other things.

I can see a definition of a function but I can’t see the function itself being called. Remember to tell the computer exactly what you want to run and when.

I’d also suggest you shy away from adding `print` functions to your `return` statements. If you must `print` from your function consider doing so on the line before your `return`.

Okay, ehm… but how can I adjust my question? I don’t understand that

You can edit a post but only within a short period of time which would’ve passed by now. If you’re still stuck then you could just add it as a reply but please keep formatting in mind for any future posts. It really does help anyone who reads the code and tries to help.

I don’t believe this is the same project, there are an unfortunate number of projects that all have a `medical insurance` in the title so just double check before adding queries. I think yours would be the portfolio project instead?

As for the code your definition seems reasonable. Your error code mentions IPython so I’d hazard a guess that you’ve altered the text of your class but not executed that class definition again (the current state of your program probably has an older definition of `ReadInsurance`). Make sure you run the code for that class definition when you edit it.

1 Like

This topic was automatically closed 41 days after the last reply. New replies are no longer allowed.