Medical Insurance Project syntax error

Hi chaps,

Been having issues with syntax of the project on this site:
https://www.codecademy.com/paths/data-science/tracks/dscp-python-fundamentals/modules/dscp-python-syntax/projects/ds-python-syntax-project

This is my code:

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

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 "script.py", 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,

Thanks.

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