Medical Insurance Project

Hello everyone ! I was doing the medical insurance project and everything was working until i got to the part where I am suppose to get a negative number for the male and I didn’t. Here is my link https://gist.github.com/e1070c051d3337b25cf1ea934b651617

Please help me understand the error.

Could you provide details of your error either the difference between what you expected and what you got or the traceback (at least the error given by the cc environment) and a link to the project itself?

I’m not quite sure what you mean by a negative number for male. I don’t believe the insurance cost should ever be negative or do you mean your the net difference of male/female costs with this formula should be negative?

*Bounced this into get-help python

Are you referring to step 6 where you’re supposed to calculate the change in the estimate in insurance costs for being male?
https://www.codecademy.com/paths/data-science/tracks/dscp-python-fundamentals/modules/dscp-python-syntax/projects/ds-python-syntax-project

" 6. Next, we want to find the difference between our new_insurance_cost and insurance_cost . To do this, let’s create a new variable called change_in_insurance_cost and set it equal to the difference between new_insurance_cost and insurance_cost .

Note: depending on the order that we subtract (eg., new_insurance_cost - insurance cost vs. insurance_cost - new_insurance_cost ), we’ll get a positive or negative version of the same number. To make this difference interpretable, let’s calculate new_insurance_cost - insurance_cost . Then we can say, “people who are four years older have estimated insurance costs that are change_in_insurance_cost dollars different, where the sign of change_in_insurance_cost tells us whether the cost is higher or lower."

1 Like

Here is the code. The hint states that the answer should be a negative number. I do get two different numbers but it does not calculate the difference. It just calculates what the male’s insurance cost is, it doesn’t calculate the actual difference.

Lines 38/39 look a bit iffy to me. Based on the formula it’s quite clear what difference should appear for values of 0 or 1 for sex as the multiplication factor is -128. You’re quite right to believe there’s a problem; even if the syntax is acceptable the parser may not interpret the code the same way you do at present.

1 Like

You know what, now that I look at it, there is an issue…
I’m looking at my code and yours and the numbers are different, yet, it passed :thinking:
I’ll keep investigating and report back.

I erased my code and went back and redid it. (and spent waaaay too long trying to discern the differences). I did get a negative number for the diff. between male and female costs.
This is my code below. The difference I can see is that your age variable when calculating BMI is different than mine. Also, side note/totally off topic-I hate that bmi is used at all in this exercise & the calculation b/c that’s a crap number and not indicative of one’s overall health.

2 Likes

@byte5660855838
I figured it out! I had copied your code into a Colab file and compared it to mine. I just edited your code and your code then produced the same answers as mine.

There’s an issue in your code here in the BMI insurance calculation:

change_in_insurance_cost = new_insurance_cost 
- insurance_cost

And in the male & female insurance costs calculation:

change_in_insurance_cost = new_insurance_cost 
- insurance_cost

if you move the part “- insurance_cost” to the same line, you get the correct calculations.

Fix these two lines and your calculations will change for those variables.

Man, that took a lot of coffee for me. haha. :coffee: :joy:

2 Likes

Im not sure I am following. When I look at your code and my code, they look the same. Ill try the lab again with a clean slate and see if that works.

Your code:

Im doing the lab again so stay tuned.

1 Like

my code produced a different result for me in Colab (the correct results).

I spent awhile looking at it (before I had ingested a full cup of coffee and then I had another cup…haha.)

But, that’s what changed the output in your code that I’d copied into Colab. It changed when I put it on the second line and then put the variable calculation on one line.

It’s line 38/39 of your second github link and probably a few others as pointed out by @lisalisaj . You cannot continue an expression on a second line unless you account for this by nesting it inside something like allows for this (e.g. parentheses or explicitly marking it with the \ line break for example). The main point being how would the parser know which expressions are grouped together and what order to execute in?

A couple of quick examples…

a = 1
+ 3

b = (1
+ 3)

c = 1\
+ 3

print(a)
Out: 1  #  UH OH! We didn't add 3. Not good.
print(b)
Out: 4   # Parentheses allow for single expression to cover multiple lines
print(c)
Out: 4  # Explicit line breaks can be used
1 Like

Just wanted to give you an update and let you know I did the lab again it worked! Thank you for your help.

1 Like