Computer Science - Class 12
Chapter 14 - Functions in python

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)

Question 2-Write definition of a method - Teachoo.JPG


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

Go Ad-free
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 14 years. He provides courses for Maths, Science, Social Science, Physics, Chemistry, Computer Science at Teachoo.