Skip to content
Question 77 of 97

Q.Ravi, a Python programmer, is working on a project in which he wants to write a function to count the number of even and odd values in the list. He has written the following code but his code is having errors. Rewrite the correct code and underline the corrections made. define EOCOUNT(L): even_no=odd_no=0 for i in range(0,len(L)) if L[i]%2=0: even_no+=1 Else: odd_no+=1 print(even_no, odd_no)

Puducherry CbseCBSE Class XII Board 2023Subjective· 2mImportance★★★★★
79% · 77/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 →

Ravi's code has four syntax errors: missing def keyword, missing colon after for, wrong assignment operator in if, and incorrect capitalization of else. The corrected function properly counts even and odd numbers by iterating through the list with correct Python syntax.

The problem tests your understanding of Python function syntax and control structures. A function definition requires the def keyword, control statements (for, if) need colons, comparison uses == (not =), and Python keywords are case-sensitive.

Let me walk through each error and its fix:

  1. Function definition keyword

    The line define EOCOUNT(L): is incorrect because Python uses def, not define, to declare functions. The correct syntax is def EOCOUNT(L):.

  2. Missing colon after for statement

    The line for i in range(0,len(L)) is missing a colon at the end. Every compound statement in Python (loops, conditionals, function definitions) must end with a colon. It should be for i in range(0,len(L)):.

  3. Assignment vs. comparison operator

    The condition if L[i]%2=0: uses a single = (assignment operator) instead of == (comparison operator). In Python, = assigns values while == tests equality. The correct condition is if L[i]%2==0:.

  4. Incorrect capitalization of else

    Python keywords are case-sensitive and must be lowercase. Else: should be else:. …

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.