Answer to Question #312226 in Python for siva

Question #312226

Repeated Numbers



Eren wants to decode a number.After lots of trial and error, he finally figured out that the number is a count of repeated single-digit integers.



Write a program to help Eren print the decoded number given a string of integers N.



Input


The first line contains a string of integers N.



Output


The output contains a single integer representing count of repeated numbers in the input.



Explanation


For N = 212311 ,


1 and 2 are repeated.Therefore, the output is 2.



Sample Input1


212311


Sample Output1


2



Sample Input2


111


Sample Output2


1


Note: This site already given answer but it was not executin

answer:

N = input()

digits = [0]*10


for ch in N:

  d = int(ch)

  digits[d] += 1



cnt = 0

for d in digits:

  if d > 1:

    cnt += 1

print(cnt)


error:

Traceback (most recent call last):

 File "main.py", line 5, in <module>

  d = int(ch)

ValueError: invalid literal for int() with base 10: ' '



1
Expert's answer
2022-03-15T16:46:09-0400
N = int(input())

digits = [0]*10

while N > 0:
    d = N%10
    N //= 10
    digits[d] += 1

cnt = 0
for d in digits:
  if d > 1:
    cnt += 1

print(cnt)

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS