# NameError: name 'estimated_cost' is not defined

**# Create calculate_insurance_cost() function below: **
### Python Functions: Medical Insurance Project
why my code have this error:

NameError: name ‘estimated_cost’ is not defined

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 person 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)
print(“The estimated insurance cost for Maria is " + str(estimated_cost) + " dollars.”)

# 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)
print(“The estimated insurance cost for Omar is " + str(estimated_cost) + " dollars.”)
#Estimate josef’s insurance cost
yusef_insurance_cost = calculate_insurance_cost(name = “yusef”, age = 39, sex = 1, bmi = 22.2, num_of_children = 0, smoker = 0)
print(“The estimated insurance cost for yusef is " + str(estimated_cost) + " dollars.”)

#difference_insurance_cost
def calculate_difference_insurance_cost():
difference_insurance_cost = omar_insurance_cost - maria_insurance_cost
return diff
print(“The difference in insurance cost is” + str(diff)+ “dollars.”)

• Do you have the link to the lesson?

→ -> → Did you try moving around the `return` and `print()` statements in the function definition?
Also, you receive the `NameError` because of scope. The variable is local and not global. ie: it’s defined inside the function so, `estimated_cost` is local to that function.