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
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)- A8% (1)
- B15% (2)
- D69% (9)
- E8% (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
SyntaxErroroccurs 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, andValueErrorare all runtime exceptions triggered by type mismatches, missing attributes, or bad values - none of which apply here. Theprintfunction 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.