Skip to content
Question 81 of 97

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')

Yanam CbseCBSE Class XII Board 2020Subjective· 2mImportance★★★★★
84% · 81/97 Questions
🔒 Locked · start free trial →

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.

  1. 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').

  2. if W = 'Hello' — = is the assignment operator; comparison needs ==. So it must be if W == 'Hello'.

  3. Missing colon — every if/else header needs a trailing colon: if W == 'Hello':.

  4. Indentation — the print() statements under if and else must be indented.

Watch out

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.