Q.Rewrite the following code in Python after removing all syntax error(s). Underline each correction done in the code. input('Enter a word',W) if W = 'Hello' print('Ok') else: print('Not Ok')
You're viewing a preview — the full solution, concept, methods & PYQ mapping are locked.
Start your 14-day free trial to unlock the full solution →The code mixes Python with other-language habits. The fixes: assign input() (one argument) to W, use == for comparison, add a colon after the if condition, and indent the print() statements.
The core issue is that the original code writes Python conditions, assignments and function calls the way other languages do. Each line has a specific error.
-
input('Enter a word',W)—input()takes only one argument, the prompt string; you cannot pass a variable as a second argument, and the returned value must be assigned to a variable. Correct form:W = input('Enter a word'). -
if W = 'Hello'—=is the assignment operator; comparison needs==. So it must beif W == 'Hello'. -
Missing colon — every
if/elseheader needs a trailing colon:if W == 'Hello':. -
Indentation — the
print()statements underifandelsemust be indented.
Using = instead of == inside an if is a very common beginner mistake. In Python, if W = 'Hello' raises a SyntaxError because = is an assignment statement, not a comparison. …
Unlock everything free for 14 days
- Full step-by-step solutions
- Concept-first explanations
- Methods, shortcuts & mistakes
- PYQ mapping + timed mock tests
Full access for 14 days. No credit card required.