Question: Now we are going to look at using functions with lists ( Section 6 . 6 ) Complete the following function, countMultiples that takes a
Now we are going to look at using functions with lists Section
Complete the following function, countMultiples that takes a list and a number as parameters and counts the number of values in the list of integers that are a multiple of the given number. In other words, think math class when you are given and told to find the first multiples. They would be Except here we will search for the multiples in our list.
Inside the function, use a for loop to scroll through the list Section Traversing Lists check if the value is a multiple of the number, and increase the count if it is a multiple. Return the count from the function.
For example, if the list of values is:
and the "number" is then we are looking for any multiple of The returned value from the function would be:
because and are all multiples of
Remember that a multiple of a number when divided by it results in hint: number multiple This is a lot like what we have used for finding an even or odd number.
Only write the function with the return value. Do not print anything out or write a main function.
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
