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

Popular posts from this blog

java - SSE Emitter : Manage timeouts and complete() -

jquery - uncaught exception: DataTables Editor - remote hosting of code not allowed -

java - How to resolve error - package com.squareup.okhttp3 doesn't exist? -