Extra_Python Functions: Medical Insurance Project-Function subtraction

Hello everyone. I have just started programming and English is not my first language, so I am sorry for any possible mistake.
I was doing the exercise specified in the object, that stated " * Create a second function to calculate the difference between the insurance costs (given as inputs) of any two individuals and print a statement saying: "The difference in insurance cost is xxx dollars."". Now, I am probably missing something about the previous lesson, but this is the best that I have managed to write down:
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(f"The estimated insurance cost for {name} is {estimated_cost} dollars.")**
maria_insurance_cost = calculate_insurance_cost(“Maria”,28,0,26.2,3,0)#this will be used as cost2
omar_insurance_cost = calculate_insurance_cost(“Omar”,35,1,22.2,0,1)#this will be used as cost1
** #Extra_difference in costs**
def difference_cost(cost1,cost2):
** return cost1-cost2, print(f"The difference in insurance cost is {cost1-cost2} dollars.")**
I thought to use the variable in which I have previously stored the result of my previous function, but it doesn’t work.
Can someone help me?

Nothing wrong with your question at all, your thought process seems correct but the code as written is an issue. As an aside see the following for a little detail about code-formatting- FAQ which makes it easier to read code posted to the forums.

At the moment your calculate_insurance function is returning two items and is therefore returning a tuple. Note that print itself is a function which does not have a standard return and would return the None object. At the moment maria_insurance_cost probably looks like (1000.0, None) under standard representation with an example value.

What would be the result of (1000.0, None) - (1250.0, None)? Hard to say? This would be throwing an error.

I’d suggest altering that first function so that the print is not included in the return. Simply putting it on the line beforehand would be easiest. There is no benefit to including it in the return. Consider doing the same for the next function as it just confuses the output.


Thank you so much! I have done what you suggested and it worked!
Thank you also for the tips about the formatting, hope I didn’t give you too much trouble.

1 Like