Counting a digit
Write code · Medium · §1.1 Digits
Complete the function solution, which returns how many times the digit d appears when the non-negative integer n is written in base 10.
Function
solution(n, d)
Constraints
nis an integer from 0 to 1,000,000,000,000,000,000 (10¹⁸).dis an integer from 0 to 9.
Examples
| n | d | result |
|---|---|---|
707070 | 7 | 3 |
123 | 4 | 0 |
Starter code
def solution(n, d):
answer = 0
return answerSolve this problem in your browser
Python runs in your browser and checks your answer right away. Hints and the answer are on the problem page.