+ 1

Write a program that takes an arbitrary positive integer as input and calculates and prints the number of digits 0 to 9 in it.

can you help me with this?

25th Dec 2020, 12:55 PM
a.m
2 Respuestas
25th Dec 2020, 1:08 PM
Roma Butaku
Roma Butaku - avatar
+ 5
To count the digits of a number several approaches can be done. ▪︎using a for loop: lst = list(map(int, input().split() or '14760645345')) if all(str(dig).isdigit() for dig in lst): # check if input are all digits for dig in sorted(set(lst)): print(f'digit {dig} - {lst.count(dig)}') ▪︎using a list comprehension: # or with a list comprehension: lst = list(map(int, input().split() or '14760645345')) [print(f'digit {dig} - {lst.count(dig)}') for dig in sorted(set(lst))]
25th Dec 2020, 4:45 PM
Lothar
Lothar - avatar