Write a program that counts the occurrences of each digit in a string. The program counts how many times a digit appears in the string. For example, if the input is "12203AB3", then the output should output 0 (1 time), 1 (1 time), 2 (2 times), 3 (2 times).

 


input_string = input("Enter a string: ")

zero = input_string.count('0')
one = input_string.count('1')
two = input_string.count('2')
three = input_string.count('3')
print(input_string)

print(f"There are 0 ({zero} time), 1 ({one} time), 2 ({two} time), 3 ({three} time) in the given string")


Output:

Enter a string: 12203AB3
12203AB3
There are 0 (1 time), 1 (1 time), 2 (2 time), 3 (2 time) in the given string

Comments