# Medical Insurance Project:Difference in Insurance costs(Task 5 and 6)

Hi chaps,

Thanks for the previous help by the community. It really gave me the confidence to continue. My confidence was shot a bit with the struggle to get the code to work.

I am trying to complete task 5 and 6.

``````Now that we have changed our age value, we want to recalculate our insurance cost. Declare a new variable called new_insurance_cost underneath the expression that increased age by 4.

Make sure you leave the line with the insurance_cost variable the same. We will use it later in our program!
``````
``````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.
``````

I am unsure how to proceed.

This my code:

``````def insurance_cost(age,sex,bmi,num_of_children,smoker):
return (250 * age) - (128 * sex) + (370 * bmi) + (425 * num_of_children) + (24000 * smoker) - 12500

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)
print("This personâ€™s insurance cost is", total_insurance_cost, "dollars.")
# Age Factor
age+=4

new_insurance_cost = insurance_cost(age, sex, bmi, num_of_children, smoker)
print("This personâ€™s insurance cost is", new_insurance_cost, "dollars.")

print(new_insurance_cost)
new_insurance_cost=input()
print(total_insurance_cost)
total_insurance_cost=input()
change_in_insurance_cost=float(new_insurance_cost)-float(total_insurance_cost)
print("Difference in insurance cost",change_in_insurance_cost)
``````

and the output:

``````This personâ€™s insurance cost is 5469.0 dollars.
This personâ€™s insurance cost is 6469.0 dollars.
6469.0
Traceback (most recent call last):
File "script.py", line 20, in <module>
new_insurance_cost=input()
EOFError: EOF when reading a line
``````

I am strugggling with

1. EOF error
2.Intrepreting the difference based on the changes in the variable
3.Outputing a string and float to explain this difference.

Any help will be greatly appreciated.

Hello! For number one (the `EOF` error) it is likely because the terminal is not interactive in that particular CC lesson (so it doesnâ€™t accept input). Just assign the variables hard coded values instead of using `input()` for this project. As for 2 and 3, I donâ€™t quite know what youâ€™re asking.

Now that we have changed our `age` value, we want to recalculate our insurance cost. Declare a new variable called `new_insurance_cost` underneath the expression that increased `age` by `4` .

Make sure you leave the line with the `insurance_cost` variable the same. We will use it later in our program!

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.

This is the revised code but I still have issues with it:

``````# create the initial variables below
def insurance_cost(age,sex,bmi,num_of_children,smoker):
return (250 * age) - (128 * sex) + (370 * bmi) + (425 * num_of_children) + (24000 * smoker) - 12500

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)
print("This personâ€™s insurance cost is", total_insurance_cost, "dollars.")
# Age Factor
age+=4

new_insurance_cost = insurance_cost(age, sex, bmi, num_of_children, smoker)
print("This personâ€™s insurance cost is", new_insurance_cost, "dollars.")

def change_in_insurance_cost(a,b):return a-b
#To calculate the difference between the original insurance cost and new insurance cost
a=print(float(new_insurance_cost))

b=print(float(total_insurance_cost))
#Assigning the values of new insurance cost to variable a and values of previous total insurance cost to b
print("Difference in insurance cost","=" ,change_in_insurance_cost)
# BMI Factor

# Male vs. Female Factor

# Extra Practice
``````

And the output:

``````This personâ€™s insurance cost is 5469.0 dollars.
This personâ€™s insurance cost is 6469.0 dollars.
6469.0
5469.0
Difference in insurance cost = <function change_in_insurance_cost at 0x7f86b5b07d08>
``````

Any help will be gladly accepted. Thanks.

With the issue in the code, `change_in_insurance_cost` is a function, which means you need to call it like this:

``````some_function(parameter1, parameter2)
``````

The way youâ€™re doing it currently is leaving off the parentheses and parameters, so youâ€™re actually getting the memory address of the `change_in_insurance_cost` function.

This is simply asking you to declare a variable called `new_insurance_cost`, and use the new value of `age` to calculate the cost of insurance for a person whose age is the new value of `age`. Do it underneath this line

``````age+=4
``````

This is telling you that you still need the `insurance_cost` variable, so donâ€™t delete it.

All you need to do here calculate the difference between `new_insurance_cost` and `insurance_cost`. How would you do that? Then, save the answer to a variable called `change_in_insurance_cost`.

With the last one, just print out `change_in_insurance_cost`, and some words explaining what it is.

1 Like

iâ€™m sorry what you just said just flew over my head.

Can you explain in simple terms with an example?

To call a function (access the `return` value/make any `print` statements inside the function actually print), you need to use the following template:

``````some_function(parameter, parameter)
``````

Notice how brackets `()` come after the name of the function and inside those brackets are the values you want to assign to the functionâ€™s arguments?

If you donâ€™t do that, and you just use the functionâ€™s name, like this:

``````some_function
``````

You are actually getting the memory address of the function-where there function is stored in the computerâ€™s memory.

Ok so how can I make the arguments total_insurance_cost and new_insurance_cost dynamic and not fixed?

Never mind I managed to understand what you meant and I solved the problem. I just pass the variable arguments and created a new variable to store the value.

1 Like