A Day at the Supermarket - Lists + Functions


#1




Hey guys,

I have completed this excercise however it is not 100% clear to me. Below is the code I used:

def fizz_count(x):
    count = 0
    for item in x:
        if item == "fizz":
            count = count + 1
    return count

What I do not understand is that we do not define x at any point. The objective of this function is to count the number of times "fizz" appears in x, so why do we not write a list (x) containing a number of "fizz"s?

When I try to include this python rejects it stating that the count returned some incorrect number of "fizz"s.
If we were to define a list, x, where would we do this?

Many thanks


#2

x is the function parameter, it serves as placeholder until you supply an argument at function call

you could add a function call and supply a list as argument


#3

what you can do is add this below return count

x = ["fizz","new","fizz"]
fizz_total = fizz_count(x)
print fizz_total


#4

Got it, thanks guys.


#5