Check sibling questions

Write definition of a method Even Sum(NUMBERS) to add those values in the list of NUMBERS, which are even.

 

Answer:

def methoodEvenSum (NUMBERS):

    sum= 0

    for i in range (len(NUMBERS)):

        if NUMBERS[i]% 2 == 0 :

            sum=sum+NUMBERS[i]

    print(sum)


Transcript

Question 2 Write definition of a method EvenSum(NUMBERS) to add those values in the list of NUMBERS, which are even. defining a function to calculate the sum of even numbers For loop which iterates from 0 to the length of the list If the number is even, then it is added to the sum assigning the variable ‘sum’ the value 0 Checking if the number is divisible by 2

  1. Computer Science - Class 12
  2. Chapter 14 - Functions in python

About the Author

Davneet Singh

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