Count the Digit X40706


Statement
 

pdf   zip   main.py

html

Write a function count_digit(d, n) that receives a single digit d (non-negative integer less than 10) and a positive integer n and returns the number of occurrences of digit d in n.

Observation

All integers are assumed written in the usual base 10.

Sample session
>>> count_digit(2, 222122)
5
>>> count_digit(0, 2020)
2
Information
Author
Jordi Delgado \& José Luis Balcázar
Language
English
Official solutions
Python
User solutions
Python