Help with this code! Cannot understand what's the bug here. Topic : Python functions

https://www.codecademy.com/paths/data-science/tracks/dscp-python-fundamentals/modules/dscp-python-functions/projects/ds-python-functions-project

^ This is the link to my code which I’m working on.

Posting the code here for reference;

Create calculate_insurance_cost() function below:

def calculate_insurance_cost(name, age, sex, bmi, num_of_children, smoker):

estimated_cost = 250age - 128sex + 370bmi + 425num_of_children + 24000*smoker - 12500

print(‘The estimated insurance cost for ’ + name + ’ is ’ + str(estimated_cost) + ’ dollars.’

return estimated_cost

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)

Omar_insurance_cost = calculate_insurance_cost(name = ‘Omar’, age = 35, sex = 1, bmi = 22.2, num_of_children = 0, smoker = 1)

Output;
It is either showing invalid syntax when I’m returning the ‘estimated_cost’ or it when I’m just calling the function. What can be changed here / how can i correct this ?

Hello @hathim, welcome to the forums! The reason you are getting an invalid syntax on the return line (at least, I assume you are), is because you are missing a closing parenthesis ) here:

specifically, at the end.

In future, whenever you get a syntaxError, and the line it’s on seems fine, always check the line above it.

3 Likes

Hey codenutrino,

Thank you so much for that. That was really silly of me. I’ve just newly dived into the coding world, so I guess I’m still a bit rusty. Anyways, thanks for that pointer. Appreciate it.

2 Likes