I want the output of the code to be something like this if the user enters a string of numbers like let's say... 122033
Enter string of numbers: 122033
0 occurs 1 time
1 occurs 1 time
2 occurs 2 times
3 occurs 2 times
def count_digits(s):
res = [0]*10
for x in s:
res[int(x)] += 1
while 0 in res:
res.remove(0)
return res
def main():
s=input("Enter string of numbers: ")
print(count_digits(s))
main()
This is the program that I have so far. At it's current state, if a user enters something like 122033 the output is:
[1,1,2,2]
Note: I cannot use collections for this.
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…