Created
April 14, 2021 08:47
-
-
Save SpirosArk/dc52d14a2b287f5cf3a84d80bc310715 to your computer and use it in GitHub Desktop.
A gist that counts from 1 to given number n, how many times "a certain digit -- here is 9 --" will appear
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def count_digit(n): | |
c = 0 | |
for i in range(0, n+1): #For to parse from 0 to given n | |
for digit in str(i): #For to parse given n's digits | |
if digit == '9': #Digit's occurence which will be counted | |
c = c + 1 | |
return c |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment