Lists + Functions


#1



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


Your code appears to raise an error, see the console window for the error message! File "python", line 7
SyntaxError: 'return' outside function


# Write your function below!
def fizz_count(x):
    count = 0
for item in x:
    if item == fizz:
        count = count + 1 
    return count


#2

fizz is supposed to be a string.

Furthermore Python cares about whitespace, you need to indent for item in x since x is the parameter taken in by the fizz_count function.

Additionally you could simplify count = count + 1 into count += 1.


#3

yeah my indentation was wrong, thanks


#4

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

where have i gone worng im lost big time

RESOLVED....double == on count _1 noticed and removeed tyvm

Oops, try again. fizz_count(['fizz', 'buzz']) returned 0 instead of the correct answer: 1


#5

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