Apr-18-2017, 12:23 AM
The following code SHOULD report the number of times that the word "fizz" appears inside of the list GroceryItems. However, I continually receive an error message saying that there is an issue with having x[y] because y is a string, and not a number.
How can I fix this script? And, this just being out of curiosity, why doesn't x[y] work? "y" is the incrementing variable in my "for" loop. It should be an integer.
How can I fix this script? And, this just being out of curiosity, why doesn't x[y] work? "y" is the incrementing variable in my "for" loop. It should be an integer.
def fizz_count(x): count = 0 for y in x: if x[y] == "fizz": count = count + 1 print count GroceryItems = ["fizz","soda", "apple", "fizz", "fizz"] fizz_count(GroceryItems)