Medical Insurance Project syntax error

Hi chaps,

Been having issues with syntax of the project on this site:

This is my code:

# create the initial variables below
def insurance_cost(age,sex,bmi,num_of_children,smoker):
  sex= 0
  bmi= 26.2

total_insurance_cost = insurance_cost(age, sex, bmi, num_of_children, smoker)
# Add insurance estimate formula below
return (250 * age) - (128 * sex) + (70 * bmi) 
+(425*num_of_children)+ (24000*smoker)-12500

print("This person’s insurance  cost is", total_insurance_cost, "dollars.")

and this error:

File "", line 11
    return (250 * age) - (128 * sex) + (70 * bmi) 
SyntaxError: 'return' outside function

I am still finding my feet with this Python syntax. Any help would be greatly appreciated,


Hello! Notice the indentation of the return statement? return statements need to be indented inside the function, like this:

|def some_func():
 |return "hello, world!"
|print("I'm out of the indentation!")

(The | marks indentation). Here’s a very simplified version of you function (notice the indentation):

|def insurance_cost(age, sex,bmi,num_of_children,smoker):
|return "something that's too long to type out"

See the indentation of the return statement?

I hope this helps!

1 Like

Thanks for the reply mate.

1 Like