Y is the name of the list lost instead of numbers bcoz in for loop its numbers?


#1



def count_small(numbers):
    total = 0
    for n in numbers:
        if n < 10:
            total = total + 1
    return total

lost = [4, 8, 15, 16, 23, 42]
small = count_small(lost)
print small


Replace this line with your code.


#2

you supply lost as argument when calling the function:

small = count_small(lost)

the argument gets then copied into the function parameter (numbers)

the advantage of this method is that your function works for multiply list simply supply the list as argument:

lost = [4, 8, 15, 16, 23, 42]
small = count_small(lost)
print count_small([3,6,7,9,1,2,45,65,32])

If you where to loop over lost, your function would only work for a single list


#3

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.