The code does exactly what I want it to do, but Code Academy doesn't like it.
I get this error:
Oops, try again. fizz_count(['fizz', 'buzz']) returned 3 instead of the correct answer: 1
Here's what the code does.
It creates a list called x
Then it loops through x making everything lower case
After that it loops through x again checking for "fizz"
The variable count is incremented accordingly
count is printed out to verify it counted the correct number of times fizz appears
#create the list x = ["Fizz", "Buzz", "FIZZ", "BUZZ", "fIzZ", "bUzZ", "cann"] print "Before anything:", x #runs through the list and makes everything lower #this standardizes the list before checking it for anything place = 0 for y in x: x[place] = y.lower() place += 1 print "Now it's all lower:", x #takes z as a placeholder for x #checks if the the list item is "fizz" #increments count if that is the case def fizz_count(z): count = 0 for y in x: if y == "fizz": count += 1 print "The number of times fizz occurs is: " + str(count) return count fizz_count(x)