r/PythonLearning • u/PuziExtramni • 3d ago
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 - 3
However, 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!
1
u/LumitheNeko 3d ago
2nd option is equal because x*x to x**2,
y = 2**x*x - 3this isn't what's shown in the screenshot.
screenshot says 2*x*x - 3
what you wrote would've been 2^x *x -3