## Posted By

a7xrturo on 11/23/13

# Digit counter

/ Published in: Python

Program that asks for a number and then a digit. Then it shows how many times the digit is in the given number.

`print('-- Digit counter --') # get inputs num = input('Enter a number > ') while not num.isdigit():    print('Number must be a positive integer! Try again.')    num = input('Enter a number > ') print('Number entered is {}'. format(num)) dig = input('Enter a digit > ') while True:    if dig.isdigit():        if int(dig) in range(0, 10):            break        else:            print('Digit must be in the range 0...9 Try again.')            dig = input('Enter a digit > ')    else:        print('Digit must be in the range 0...9 Try again.')        dig = input('Enter a digit > ') print('The digit entered is {}'.format(dig)) # increments counter every time digit is found in numbercounter = 0 for i in num:    if dig == i:        counter += 1 print('The number of {0} \'s in {1} is {2}'.format(dig, num, counter))`