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).
Code
str = input("Enter a string: ")for i in range(len(str)):if str[i].isdigit():# no repetitionif str[i] not in str[:i]:print(str[i], " (", str.count(str[i]), " times)", sep="")
0 Comments
Post a Comment