Check sibling questions
Computer Science - Class 12
Solutions to CBSE Sample Paper - Computer Science Class 12

The code given below accepts a list of numbers as an argument and returns the sum of all even numbers in the list. Observe the following code carefully and rewrite it after removing all syntax and logical errors. Underline all the corrections made.

def sum_even(lst):

  sum = 0

  for i in range(lst):

     if i % 2 = 0:

     sum += i

     else

       continue

  return sum

Answer:

Answer by student

Corrected code for sum of all even numbers in a list - Teachoo.png

Detailed answer by teachoo

The rest of the post is locked. Join Teachoo Black to see the full post.

Ask a doubt
Davneet Singh's photo - Co-founder, Teachoo

Made by

Davneet Singh

Davneet Singh has done his B.Tech from Indian Institute of Technology, Kanpur. He has been teaching from the past 13 years. He provides courses for Maths, Science, Social Science, Physics, Chemistry, Computer Science at Teachoo.