Hello everyone, I am currently taking a course in Data Science and I am dealing with Python. As part of the python program, there is an excercise where we can use a function to calculate someone’s medical insurance cost. The code looks like this
# Create calculate_insurance_cost() function below:
def calculate_insurance_cost(age, sex, bmi, num_of_children, smoker, name):
estimated_cost = 250*age - 128*sex + 370*bmi + 425*num_of_children + 24000*smoker - 12500
print('The estimated cost for ' + name + ' is ' + str(estimated_cost) + ' dollars')
return estimated_cost
# Estimate Maria's insurance cost
maria_insurance_cost = calculate_insurance_cost(age = 28, sex = 0, bmi = 26.2, num_of_children = 3, smoker = 0, name = 'Maria')
# Estimate Omar's insurance cost
omar_insurance_cost = calculate_insurance_cost(age = 35, sex = 1, bmi = 22.2, num_of_children = 0, smoker = 1, name = 'Omar')
and the output is:
The estimated cost for Maria is 5469.0 dollars
The estimated cost for Omar is 28336.0 dollars
my question is: why does the output side show both sentences? Both variables maria_insurance_cost and omar_insurance_cost have not been printed using the print() function, so in my mind, in order to display both sentences, I should add the code below: print(maria_insurance_cost) and print(omar_insurance_cost). However, I cannot understand how this part of the code (see below) is enough to call the function, while if I create a random variable (e.g. dog_name = ‘Fuffy’) it will not be displayed unless I use the print() funcion.
# Estimate Maria's insurance cost
maria_insurance_cost = calculate_insurance_cost(age = 28, sex = 0, bmi = 26.2, num_of_children = 3, smoker = 0, name = 'Maria')
# Estimate Omar's insurance cost
omar_insurance_cost = calculate_insurance_cost(age = 35, sex = 1, bmi = 22.2, num_of_children = 0, smoker = 1, name = 'Omar')
Hope the question is clear and thank you very much for your help