![miaa1024](/avatars/48465.jpg)
miaa1024
23.04.2020 •
Computers and Technology
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.
Solved
Show answers
More tips
- C Computers and Internet Best Antivirus: How to Choose Protection for Your Computer?...
- L Legal consultation What Documents Are Required for a Russian Passport?...
- S Sport How to Choose Tennis Rackets?...
- H Health and Medicine AKDS Vaccination: Ensure Your Child s Safety...
- H Health and Medicine Naskol ko Opasen Ukus Kleshcha i Kak Ego Raspoznat...
- C Computers and Internet How to Delete Your Account on Odnoklassniki...
- H Health and Medicine What to Do When Your Jaw Locks Up?...
- G Goods and services What Are the Most Popular Services?...
- P Philosophy How did the concept of module arise in computer science?...
Answers on questions: Computers and Technology
- C Computers and Technology Computer-animated tigers appearing alongside the image of a real-life group dancing on stage is an example of . * augmented reality livestreaming virtual reality motion capture...
- C Computers and Technology HELP ASAP PLZ! A shape with a Wipe animation wipes from left to right, but Paco wants it to wipe from right to left. What button should he click on the Animations tab to change the...
- C Computers and Technology Write a program to output the following quote by Edsger W. Dijkstra: Computer Science is no more about computers than astronomy is about telescopes - Edsger W. Dijkstra Hint: Remember...
- S Social Studies Ppplllzz correct answers only the term arab refers to a religion an ethnicity a philosophy a nationality...
- B Biology What are the three mechanisms for reproductive isolation?...
- M Mathematics Asquare pyramid that is 20 meters tall is cleanly sliced through by a laser, 1.5 meters above its base (this leaves a shape similar to a prism). if its base has an area of 6 square...
- B Biology The cell walls of plant cells are made of what materials...
- M Mathematics Which explanation can be used to derive the formula for the circumference of a circle? a. find the length of the radius. then find the circumference. use the square of the radius to...
- M Mathematics Find the values of the variables in the parallelogram. the diagram is not drawn to scale. use fear rams involving parallel lines and the sum of the angles of a triangle....
- M Mathematics How do temperature humidity and pressure vary within air mass...
Ответ:
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: link
Ответ:
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.Ответ: