Hi everyone,
Can someone help me to check my code whether it’s the correct answer? I can’t seem to do it because it keeps giving me Identation Error which I don’t understand how I got that.
Can you post the code (correctly formatted; see this post), please?
One way to make sure all the indentation is the same (either all tabs or all spaces) is to delete all the indentation, and then use one (tab or space) indentation method to correctly indent all of the code again.
Below the line where bmi was increased by 3.1 , rewrite the insurance cost formula and assign it to the variable name new_insurance_cost . This is the question.
BMI = 26.
BMI += 3.1
new_insurance_cost - insurance_cost ← This is what I wrote so far, below this is where I used insurance cost the first time.
age = 28
new_insurance_cost
change_in_insurance_cost
new_insurance_cost - insurance_cost
print( “The change in cost of insurance after increasing the age by 4 years is XXX dollars.” + str(change_in_insurance_cost) + " dollars " )
To assign a value to a variable, you need to write:
some_variable = "some value"
^
|
notice the equal sign?
It doesn’t appear that you’ve done that:
It seems like you’re simply making these calculations, but not saving them anywhere. What is the bmi formula? And how does the exercise want you to re-write it?
Ok. Notice how you aren’t assigning any values to the variables below the age = 28 line? That means nothing you compute below there is going to do anything or be saved.
I don’t know the insurance cost formula or what calculations to save, but when I save the code I wrote, it says that line 9 new_insurance_cost is not defined.
But at that point in the code there is no new_insurance_cost variable. You personally might have an idea of what that might be but the Python interpreter does not, it cannot find that name so it throws an error.
If I asked you to tell me the numeric value of x-y but never gave you x or y there’s not much you can do. This is a similar issue.
Review some of the previous posts that state how you can actually store values to a variable-
When I put in the values for new_insurance_cost it says that “sex” is not defined. new_insurance_cost = 250 * age - 128 * sex + 370 * bmi + 425 * num_of_children + 24000 * smoker - 12500