"""
write a method to count the number of 2's in range n
"""

# psudo code:
# given n
# iterate through range n
# cast of of the numbers into strings
# start a counter
# if anything in string = 2, counter += 1
# counter is number of 2's

def count2():

"""
write a method to count the number of 2's in range n
"""

# psudo code:
# given n
# iterate through range n
# cast of of the numbers into strings
# start a counter
# if anything in string = 2, counter += 1
# counter is number of 2's

def count2(d, n):
    sd = str(d)
    return sum(str(i).count(sd) for i in range(n+1))

Update 18.4_count_2s.py