Python Classes: Medical Insurance Project

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.

Here’s the link to my code: Codecademy export · GitHub

Indentation error is cause by some sort of inconsistent tab vs. spaces issue.

I would transport the code to a text editor (vs code or sublime are popular) and just made sure that all formatting is tabs or spaces (but not mixed).

1 Like

I tried but it doesnt work as well :frowning:

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.

Hi. I’m Trying to do the project and I got stuck can anyone help me?

What is your question? Please make sure you post properly formatted code as well.

I was having trouble with rewriting the insurance cost formula and assigning it to the variable name new_insurance_cost

Can you be more specific, please? Maybe post the code you’re working with and point out where things start to go wrong?

  1. 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 - 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?

1 Like

They want me to re write the insurance cost formula not the bmi.

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.

1 Like

Ok. What do I need to do ?

You need to re-write the insurance cost formula, and save some calculations to a variable. To save a value to a variable, you can use:

some_var = "some value"
some_other_var = 5#some integer value
another_var = False #some boolean value
#and so on
1 Like

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.

That’s because it isn’t. You have written:

new_insurance_cost - insurance_cost

There is nothing being defined there.

1 Like

I did that because I had to find the difference between insurance_cost and new_insurance_cost. Are you familiar with this project?

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-

1 Like

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

Can anyone help me? Im not sure on what to do.