Skip to content

Instantly share code, notes, and snippets.

@SpirosArk
Created April 14, 2021 08:47
Show Gist options
  • Save SpirosArk/dc52d14a2b287f5cf3a84d80bc310715 to your computer and use it in GitHub Desktop.
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
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