Jun-16-2021, 03:23 PM
Hello
I'm learning python, and have an exercise to do in order to practice bracketing operators. The exercise is to code the following formula:
3x3 – 2x2 + 3x - 1
with x being either 0, 1, or -1.
assign the result to y.
The problem:
The values of y (according to the exercise) should then be:
if x=0 then y is -1
if x = 1 then y is 3.0
if x = -1 then y is -9.0
However, my results are:
results:
0 -> -1.0
1 -> 25.0
-1 -> -35.0
My code
Is the exercise correct or is my code off? Please help with suggestions / corrections!
Many thanks
I'm learning python, and have an exercise to do in order to practice bracketing operators. The exercise is to code the following formula:
3x3 – 2x2 + 3x - 1
with x being either 0, 1, or -1.
assign the result to y.
The problem:
The values of y (according to the exercise) should then be:
if x=0 then y is -1
if x = 1 then y is 3.0
if x = -1 then y is -9.0
However, my results are:
results:
0 -> -1.0
1 -> 25.0
-1 -> -35.0
My code
x = 0 x = float(x) y = (((3*x) ** 3) - ((2*x) ** 2) + ((3 * x) - 1)) print (x) print (y)Clearly something is not quite correct. I've broken the formula down into steps in code, and also worked it through on paper. I'm getting the same results.
Is the exercise correct or is my code off? Please help with suggestions / corrections!
Many thanks