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 6.6)
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 '3' and told to find the first 5 multiples. They would be 3,6,9,12,15. Except here we will search for the multiples in our list.
Inside the function, use a for loop to scroll through the list (Section 6.1 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:
[17,25,5,30,100,96,48,5,14,30]
and the "number" is 5, then we are looking for any multiple of 5. The returned value from the function would be:
6
because 25,5,30,100,5, and 30 are all multiples of 5.
*Remember that a multiple of a number when divided by it, results in 0(hint: number % multiple ==0). 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 blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!