Question 7 from Lab 3 of Berkeley's CS61A course says:The following examples of recursive functions show some examples of common recursion mistakes. Fix them so that they work as intended. [...]def even_digits(n):    Return the percentage of digits in n that are even.    >>> even_digits(23479837) # 3 / 8    0.375        if n == 0:        return num_digits / num_evens    num_digits, num_evens = 0, 0    if n % 2 == 0:        counter += 1    num_evens += 1    return (even_digits(n // 10) + num_evens) / counterAs per the assignment, below code is suppose to solve this problem, recursively (MUST not be non-recursive).def even_digits(n, count_even = 0, count = 0):    Return the percentage of digits in n that are even.    >>> even_digits(23479837) # 3 / 8    0.375        if n == 0:        return count_even / count    if (n % 2) == 0:        return even_digits(n // 10, count_even + 1, count + 1)    else:        return even_digits(n // 10, count_even, count + 1)Is this code readable? Can we improve this solution?
Percentage of digits in n that are even
python;python 3.x;recursion
There is a serious error in your code. If the function is called as even_digits(0), then it causes the following error:ZeroDivisionError: integer division or modulo by zerosince in the first if you divide by count which is 0.So, before improving the code, you should check if it is correct.ADDED:THE CASE OF n = 0It is interesting to understand what should be the result in case the input (that is n) is 0. The problem is labeled as: Percentage of digits in n that are evenand the natural interpretation is:Percentage of digits in the decimal representation of n that are evenSo, what result should give the function when provided with the value 0? I argue it should be 1, since every decimal representation of 0 has only zeroes as digits, so it has a 100% even digits.