10. A Day at the Supermarket - 4.Lists + Functions


#1

<PLEASE USE THE FOLLOWING TEMPLATE TO HELP YOU CREATE A GREAT POST!>

<Below this line, add a link to the EXACT exercise that you are stuck at.>
https://www.codecademy.com/courses/learn-python/lessons/a-day-at-the-supermarket/exercises/lists--functions?action=lesson_resume

<In what way does your code behave incorrectly? Include ALL error messages.>
fizz_count([‘fIzZ’, 7, ‘fizz’, ‘fIzZ’, 1, 6]) returned 0 instead of the correct answer: 1

<What do you expect to happen instead?>
Not sure why I am getting an error message listing list items which do NOT feature in my list!

```python

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

ello = [‘fiz’,‘fizz’,‘fizz’]
howmanytimes = fizz_count(ello)
print howmanytimes

<do not remove the three backticks above>

#2

Check your indentation. Remember, Python runs the code by how it’s indented. For example, a conditional expression like if runs the code that is indented beneath it when the conditional expression is true.

        # IF item is equal to 'fizz', then the indented
        # codeblock runs. Else, it skips over it.
        if item == 'fizz':
            # everything that is indented here is part of
            # `if` codeblock.  It only runs IF item == 'fizz'.
            count = count + 1

Check your code for proper indentation where it’s needed to define the code blocks for things like def, for, and if.


#3

Thanks a lot for responding promptly.
I just checked the forums and seems like a lot of people have been stumbling on this very exercise due to the strange error messages it spits out.
In any case, I re-wrote my code and it is working now. I removed the last 3 lines of my code and replaced it with a print statement. :neutral_face:


#4

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