syntax error 'return' outside function in python -
i trying count word fizz using python. giving me error.
def fizz_count(x): count =0 item in x : if item== "fizz": count=count+1 return count item= ["fizz","cat", "fizz", "dog", "fizz"] example= fizz_count(item) print example
i checked indentation still not work. doing wrong?
your indentation seems incorrect, , should not have first return count
(why return count
define it??).
def fizz_count(x): count = 0 item in x: if item == "fizz": count += 1 # equivalent count = count + 1 return count item = ["fizz", "cat", "fizz", "dog", "fizz"] example = fizz_count(item) print example
Comments
Post a Comment