# Medical Insurance Project

Hello, I’m new to Codecademy and I’m struggling with the project on Medical Insurance Cost for the lesson on Python functions.

Here is my code:

# Create calculate_insurance_cost() function below:

def calculate_insurance_cost(age, sex, bmi, num_of_children, smoker, name):
estimated_cost = 250age - 128sex + 370bmi + 425num_of_children + 24000*smoker - 12500
output = print(“The estimated insurance cost for " + name + " is " + str(estimated_cost) + " dollars”)
return output, estimated_cost

# Estimate Maria’s insurance cost

maria_insurance_cost = calculate_insurance_cost(28, 0, 26.2, 3, 0, “Maria”)

# Estimate Omar’s insurance cost

omar_insurance_cost = calculate_insurance_cost(35, 1, 22.2, 0, 1, “Omar”)

# Estimate John’s insurance cost

john_insurance_cost = calculate_insurance_cost(28, 1, 28, 0, 0, “John”)

# Estimate differences in insurance cost between Maria and Omar

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

maria_insurance_cost_1 = calculate_insurance_cost_1(28, 0, 26.2, 3, 0)

omar_insurance_cost_1 = calculate_insurance_cost_1(35, 1, 22.2, 0, 1)

def different_insurance_cost(maria_cost, omar_cost):
diff_insurance_cost = maria_insurance_cost_1 - omar_insurance_cost_1
print(“The difference in insurance cost is " + diff_insurance_cost + " dollars.”)

different_insurance_cost(maria_insurance_cost_1, omar_insurance_cost_1)

It’s giving the following error but I’m not sure why: TypeError: unsupported operand type(s) for -: ‘NoneType’ and ‘NoneType’. Could anyone help on this? thank you!

Hello, there seems to be a few technical/syntax issues going on here but I will first address the main point. The code is giving that error because you are attempting to subtract two “functions” data type rather than two “values” data type. For example if you would run the function you will get a tuple like this (‘None’, 5469) for Maria and a tuple (“None”, 28336) for Omar. Thats why None - None is throwing an error.

There are multiple ways to fix this. Its not a good habit to have a print statement inside the function best to use it outside. If you are returning two values like output, estimated cost. You can do the following:

maria, omar = different_insurance_cost(maria_insurance_cost, omar_insurance_cost)

This will allow you to acces the tuples of each seperately in which case you can use the index to grab the value. However a better practice would be to:
def calculate_insurance_cost(age, sex, bmi, num_of_children, smoker, name):
estimated_cost = 250age - 128sex + 370bmi + 425num_of_children + 24000*smoker - 12500

# output = print(“The estimated insurance cost for " + name + " is " + str(estimated_cost) + " dollars”)

``````return estimated_cost, name
``````

maria_insurance_cost, name = calculate_insurance_cost(28, 0, 26.2, 3, 0, “Maria”)
print(“The estimated cost for {} is {}”.format(name, maria_insurance_cost))

# Repeat for rest

omar_insurance_cost = calculate_insurance_cost(35, 1, 22.2, 0, 1, “Omar”)
john_insurance_cost = calculate_insurance_cost(28, 1, 28, 0, 0, “John”)

def different_insurance_cost(maria_cost, omar_cost):
return maria_cost, omar_cost

# you can also use an if statement to check whose insurance cost is larger otherwise you will get a result with a minus sign like, -1000 for example or you can use an abs() function.

maria,omar = different_insurance_cost(maria_insurance_cost, omar_insurance_cost)
print(omar[0])

Something like this will be cleaner. Also, side note: Its better to post a link to the .ipynb notebook or have a link where reading the code is a little better.

Hope this helps!