4/12 Right code, wrong results?


#1



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


The error message says this, "fizz_count(['buzz', 'fizz', 'fizz', 'fIzZ', 'fizz', 'fizz']) returned 0 instead of the correct answer: 4".


I'm just confused because I looked at the example, directions, and other people's posts and they appear to be getting the question correct with the same exact answer. Any help would be appreciated.


 
def fizz_count(x):
    count = 0
    for i in x:
        if i == "fizz":
            count = count + 1
        return count
        
x = ["fizz","cat","fizz"]
fizz = fizz_count(x)
print fizz


#2

a function ends the moment a return keyword is reached

If the return keyword is reached in a loop, the loop simply breaks


#3

i don't understand. How do I stop this from happening?


#4

By placing return outside the for loop


#5

So it was an indentation error?


#6

No, indention error is when you use inconsistent indention, for example:

def example():
   print "this is"
        print "an indention error"

your program was syntax wise correctly indented, the design/flow was just not right


#7

Ah okay. I think I get it now. Thank you for your help.


#8

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