Count the occurrence of digit K in a given number N using Recursion | Function to count the digit K in the given number N ; Extracting least significant digit ; Driver Code
def countdigits ( n , k ) : NEW_LINE INDENT if n == 0 : NEW_LINE INDENT return 0 NEW_LINE DEDENT digit = n % 10 NEW_LINE if digit == k : NEW_LINE INDENT return 1 + countdigits ( n / 10 , k ) NEW_LINE DEDENT return countdigits ( n / 10 , k ) NEW_LINE DEDENT if __name__ == " _ _ main _ _ " : NEW_LINE INDENT n = 1000 ; NEW_LINE k = 0 ; NEW_LINE print ( countdigits ( n , k ) ) NEW_LINE DEDENT