81.4k views
1 vote
Define a function below, count_over_100, which takes a list of numbers as an argument. Complete the function to count how many of the numbers in the list are greater than 100. The recommended approach for this: (1) create a variable to hold the current count and initialize it to zero, (2) use a for loop to process each element of the list, adding one to your current count if it fits the criteria, (3) return the count at the end.

1 Answer

1 vote

Answer:

In Python:

def count_over_100(mylist):

kount = 0

for i in range(len(mylist)):

if mylist[i] > 100:

kount+=1

return kount

Step-by-step explanation:

This defines the function

def count_over_100(mylist):

(1) This initializes kount to 0

kount = 0

(2) This iterates through the loop

for i in range(len(mylist)):

If current list element is greater tha 100, kount is incremented by 1

if mylist[i] > 100:

kount+=1

This returns kount

return kount

User Ryota
by
3.6k points