nerdexam
Python_Institute

PCEP-30-02 · Question #95

What is the output of the following snippet? ``python y = 2 + 3 * 5. print(y) ``

The correct answer is C. 17.0. Option C (17.0) is correct because Python's operator precedence evaluates multiplication before addition, so 3 5. is computed first (yielding 15.0), then 2 + 15.0 = 17.0. The trailing dot in 5. is valid Python syntax for a float literal (5.0), and since one operand is a float…

Question

What is the output of the following snippet?
y = 2 + 3 * 5.
print(y)

Options

  • A25.0
  • BThe snippet will cause an execution error.
  • C17.0
  • D17

How the community answered

(25 responses)
  • A
    4% (1)
  • B
    4% (1)
  • C
    80% (20)
  • D
    12% (3)

Explanation

Option C (17.0) is correct because Python's operator precedence evaluates multiplication before addition, so 3 * 5. is computed first (yielding 15.0), then 2 + 15.0 = 17.0. The trailing dot in 5. is valid Python syntax for a float literal (5.0), and since one operand is a float, the entire result is promoted to float.

Why the distractors are wrong:

  • A (25.0): This would result from left-to-right evaluation ((2 + 3) * 5. = 25.0), ignoring that * has higher precedence than +.
  • B (execution error): 5. is perfectly legal Python - a trailing dot is a valid way to write a float literal; no error occurs.
  • D (17): The integer 17 would only result if all operands were integers, but the float 5. forces the result to be 17.0, not 17.

Memory tip: Remember "PEMDAS" for precedence, and "one float infects the result" - whenever any operand in an arithmetic expression is a float, Python returns a float. Watch for sneaky float literals like 5. on exams.

Community Discussion

No community discussion yet for this question.

Full PCEP-30-02 Practice