The function below takes one parameter: a list of integers (num_list). Complete the function to count how many of the numbers in the list are even. As discussed in lecture, this question uses the 'visit every element of a collection' pattern, the 'is a number even' pattern, and the 'count' pattern.

Respuesta :

Answer:

following are the method definition to this question:

def count_even_integers(num_list): #defining a method, that takes num_list as a parameter  

   even_count = 0 #defining variable and assign 0

   for x in num_list: #defining loop that check all numbers  

       if(x%2==0): #define condition to check even number

           even_count =even_count+ 1 # increment value by 1

   return even_count # return even_count value

num_list=[10, 20, 30, 40] #defining list of integer

x=count_even_integers(num_list) #calling the method store its return value

print (x) #print value

Output:

4

Explanation:

In the given python program, a method "count_even_integers" is defined, that passes the value, that is "num_list" in its, inside the method, a variable "even_count" is declared, that assigns the value that is 0.

  • Inside the method, a for loop is declared, that uses the conditional statement in which and if block is used, that checks even number condition.
  • Inside the block, even_count value is increment by one and return its value, then we call the method, and store the value in variable x and print its value.  

The function that takes one parameter and count the numbers that are even number is written as follows:

def count_even_number(num_list):

   count = 0

   for i in num_list:

       if i%2 == 0:

           count += 1

   return count

print(count_even_number([10, 33, 53, 45, 7, 6]))

A function named  count_even_number is declared and the parameter is num_list.

Then a variable named count is created and initialise with 0.

Then a for loop is used to loop through the num_list.

if the remainder of when the lopped value is divided by 2 is equals to zero the count variable increase.

Then the count is returned.

The print function is used to call the function with it parameter.

learn more: https://brainly.com/question/15772977?referrer=searchResults

Ver imagen vintechnology