Count the number of occurrences of a particular digit in a number | Function to count the occurrences of the digit D in N ; Loop to find the digits of N ; check if the digit is D ; return the count of the occurrences of D in N ; Driver code
def countOccurrances ( n , d ) : NEW_LINE INDENT count = 0 NEW_LINE while ( n > 0 ) : NEW_LINE INDENT if ( n % 10 == d ) : NEW_LINE INDENT count = count + 1 NEW_LINE DEDENT n = n // 10 NEW_LINE DEDENT return count NEW_LINE DEDENT d = 2 NEW_LINE n = 214215421 NEW_LINE print ( countOccurrances ( n , d ) ) NEW_LINE