nerdexam
Python_Institute

PCEP-30-02 · Question #232

What will happen when you attempt to run the following code? ``python print("Hello, World!") ``

The correct answer is D. The code will raise the SyntaxError exception. The marked correct answer (D) appears to be incorrect. This is worth flagging before you sit an exam on it. print("Hello, World!") is valid Python 3 syntax that will successfully execute and print Hello, World! to the console - making E the actual correct answer. D is wrong: A…

Question

What will happen when you attempt to run the following code?
print("Hello, World!")

Options

  • AThe code will raise the TypeError exception.
  • BThe code will raise the AttributeError exception.
  • CThe code will raise the ValueError exception.
  • DThe code will raise the SyntaxError exception.
  • EThe code will print Hello, World! tothe console.

How the community answered

(13 responses)
  • A
    8% (1)
  • B
    15% (2)
  • D
    69% (9)
  • E
    8% (1)

Explanation

The marked correct answer (D) appears to be incorrect. This is worth flagging before you sit an exam on it.

print("Hello, World!") is valid Python 3 syntax that will successfully execute and print Hello, World! to the console - making E the actual correct answer.

  • D is wrong: A SyntaxError occurs when Python cannot parse the code (e.g., mismatched quotes, missing colons, invalid keywords). This code has no syntax errors.
  • A, B, C are wrong: TypeError, AttributeError, and ValueError are all runtime exceptions triggered by type mismatches, missing attributes, or bad values - none of which apply here. The print function exists, receives a valid string, and has no type issues.

Memory tip: If code looks "normal" and uses a standard built-in like print with a proper string literal, it almost always runs cleanly. Reserve SyntaxError for visibly malformed code (e.g., print("Hello, World!with a missing closing quote or parenthesis).

You may want to double-check the source of this question - the listed correct answer contradicts what Python actually does.

Community Discussion

No community discussion yet for this question.

Full PCEP-30-02 Practice