This is what’s in my code:
age = 28
sex = 0
bmi = 26.2
num_of_children = 3
smoker = 0
insurance_cost = 250∗age−128∗sex
+370∗bmi+425∗num_of_children
+24000∗smoker−12500
And this is the syntax error I’m getting, but I don’t understand why:
File “script.py”, line 9
insurance_cost = 250∗age−128∗sex
^ (the carrot’s under sex)
SyntaxError: invalid character in identifier
It means that you have an invalid character. Probably the asterisk.
I copied your code and got the same error in Colab. Yet, when I replaced the " * " it worked.
Sometimes if you copy characters like that they don’t translate(b/c there’s junk “behind the scenes” say, if it’s copied from Word) to the environment you’re trying to run them in.
1 Like
Thanks so much- I think that’s exactly it. I did copy and paste it from the instructions.
2 Likes
I can’t figure out where this syntax error is from now.
What’s the link to this lesson?
To display the string in the terminal, the variable estimated_cost
needs to be converted to a string in your print()
statement.
But you also forgot the return
statement in your function (which is I think step 3 of this lesson on functions?). def calculate_insurance_cost()
Also you forgot name = "Maria"
when defining the variable maria_insurance_cost
:
maria_insurance_cost = calculate_insurance_cost(name = "Maria", age = 28, sex = 0, bmi = 26.2, num_of_children = 3, smoker = 0)
1 Like