4. Lists + Functions


#1

I don't understand what's wrong with the code below, but I keep getting a weird message. Every time I submit the code, I get a different error message but similar. For example I can get

"fizz_count(['fIzZ', 'fizz', 'fizz', 1, 'fizz', 'fIzZ', 1, 'fizz']) returned 1 instead of the correct answer: 4" or

"fizz_count(['fizz', 'fizz', 'buzz', 'fizz', 'buzz']) returned 1 instead of the correct answer: 3" or

"fizz_count(['fIzZ', 10, 1, 9]) returned None instead of the correct answer: 0"

I don't get it. Here is my code.

def fizz_count(x):
count = 0
for y in x:
if y == "fizz":
count = count + 1
return count
item = ["fizz", "fizz", "wink", "fizz", "wink"]
amount = fizz_count(item)
print amount


#2

They are indented btw


#3

Your code works for me, so the problem is in your indendations. Please post the indented code to display for us the indentations. Add three spaces before your code to do this.


#4

I played with the indentations for a short time and I soon got it. The return count was on the same line as the count = count + 1.


#5

Nice that you got it by yourself! :slight_smile:


#6

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