This is the code which i have written for medical insurance project under functions lesson
function to find the cost of insurance with formula given in the exercise
def calculate_insurance_cost(name,age,sex,bmi,num_of_children,smoker):
estimated_cost=250age-128sex+370bmi+425num_of_children+24000*smoker-12500
acknowledgement =“The estimated insurance cost for “+name+” is “+str(estimated_cost)+” dollars.”
print(acknowledgement)
return estimated_cost,acknowledgement
maria_insurance_cost = calculate_insurance_cost(“Maria”,28,0,26.2,3,0)
omar_insurance_cost = calculate_insurance_cost(“Omar”,35,1,22.2,0,1)
my_insurance_cost=calculate_insurance_cost(“Anas”,28,1,24.1,0,0)
Function find the difference between cost of insurance of two persons below
def difference(cost1,cost2):
diff=cost1-cost2
print(“The difference in insurance between 1st and 2nd person”,diff,“dollars”)
difference(omar_insurance_cost,my_insurance_cost)
When i run the code, the below output is shown with error.
The estimated insurance cost for Maria is 5469.0 dollars.
The estimated insurance cost for Omar is 28336.0 dollars.
The estimated insurance cost for Anas is 3289.0 dollars.
Traceback (most recent call last):
File “script.py”, line 19, in
difference(omar_insurance_cost,my_insurance_cost)
File “script.py”, line 16, in difference
diff=cost1-cost2
TypeError: unsupported operand type(s) for -: ‘tuple’ and ‘tuple’
I was trying to assign one of the values of returned values of a the first function as an argument to second function.
Does anybody know how to do that?