I know this is question is answered but I still need help with List and Functions at A Day at The Supermarket


#1


https://www.codecademy.com/en/courses/python-beginner-en-IZ9Ra/0/4?curriculum_id=4f89dab3d788890003000096


returns wrong value. Python says should have returned more "List" than I actually have in key.
last change I made in code below say it returned 1 instead of 2


# Write your function below!
def fizz_count(x):                  #is x above the same as the X ["string list] below?
    count=0
    for item in x:                     # So I can create the variable item to look in x[]?
        if item =="fizz":
            count=count+1
            return count
    x=["fizz","Fizz","a","B"]
print fizz_count
                                                            #is this why x is in fizz_count(x) so it can be passed?
                                                         # if x in fizz_count(y) would my list have to be y=["""""]?'''


#2

x is defined as the local list, which we pass to the function:

print fizz_count(["fizz","Fizz","a","B"])

#3

ok I feel stupid.
If I type print fizz_count(x) I get Traceback (most recent call last):
File "python", line 9, in
NameError: name 'x' is not defined

x is the variable that fiz_count () is looking for right?


#4

def fizz_count(x):
    # code
    return count

print fizz_count(["fizz","Fizz","a","B"])

#7

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