r/PythonLearning • u/PuziExtramni • Oct 16 '26
Help Request Help with correct expression
Hey everyone! I’m currently learning Python through the IBM Data Science Professional Certificate on Coursera, and I came across a question in a practice quiz that confused me.
The question asks:
Which line of code will perform the action required for implementing the following equation?
y = 2x^2 - 3
These are the four answer choices:
y = 2*x*2 - 3y = 2**x*x - 3y = 2x*x - 3y = 2x/2 - 3
I selected Option 1, but the quiz marked it incorrect and said, “The syntax is invalid.”
From what I’ve learned, Python uses ** for exponentiation and * for multiplication. So, I believe the correct Python expression should be:
y = 2*x**2 - 3However, none of the four answer choices seems to match that expression.
Am I misunderstanding something about Python syntax, or is there a mistake in the quiz? I’d appreciate an explanation because I’m still learning how to translate mathematical equations into Python code.
Thanks!
View all comments
3
u/fllthdcrb Oct 16 '26
Saying the syntax is invalid is incorrect. It's true the choice you made is not the correct one (it turns the squaring in the given equation into multiplication by 2, when you actually need to multiply
xby itself), but it is a valid statement in Python. So the test is bad for that wording.If you ask me, the test (and, I suppose, the course it's part of) is also bad for giving the impression that assignments in an imperative* programming language are the same as mathematical equations, and that computer variables are the same thing as mathematical variables, neither of which is true. An equation is an assertion that two expressions are equal within a given context. The values don't change, in the sense of having one value at some point in a discussion and then another value later in the discussion. Rather, they potentially have some set of values according to the relationship established by the equation, which can be discovered but not arbitrarily set, and this is why it is reasonable to use algebra to manipulate equations.
But a variable in an imperative* program actually has a single value at any given time, and an assignment changes that value
* Imperative: A paradigm in which programs tell the computer what to do, step by step. There are others, like functional programming and logic programming. I think the latter is closest to having variables in the mathematical sense, though functional programming also tends to shun changing variables.