SOMEONE PLEASE HELP ME! Maximum Recursion Depth Exceeded


#1

Note: THIS QUESTION IS EDITED FROM ORIGINAL CODE
In the above example, we define a function count_small that has one argument, numbers.
We initialize a variable total that we can use in the for loop.
For each item n in numbers, if n is less than 10, we increment total.
After the for loop, we return total.
After the function definition, we create an array of numbers called lost.

This is my code:

def fizz_count(x):
(1 ind) count = 0

(1 ind) for item in str(x):
(2 ind) if item == "fizz":
(3 ind) count = count + 1
(1 ind) return fizz_count(x)

And this is the error I received:
an exception was raised for fizz_count(['fizz', 'buzz']): maximum recursion depth exceeded while getting the repr of a list


#2

Hi @alexandrak1989 ,

Because your code is not formatted, it is difficult for other users to read and debug it. As code is being posted, you can format it by selecting it, and then by clicking the </> button above the editing area. This will enable us to see important details, such as the indentation and underscores.

Since your indentation is not visible, you'll have to check that. But there is a problem here:

def fizz_count(str(x)):

In the header of the function definition, use a variable, not a function call, as the parameter. It should be ...

def fizz_count(x):

#3

Hello,
Thank you so much for your help. This is my new code with indentations, and the new error:

def fizz_count(x):
one indentation count = 0
one indentation for item in x:
two indentations if item == "fizz":
three indentations count = count + 1
three indentations return fizz_count

error: Oops, try again. fizz_count(['fizz', 'buzz']) returned instead of the correct answer: 1