0
How can I make the letters measured in the percentage of this code be those of the user input and not those of the function?
2 ответов
+ 4
Just do like this
text = input()
def count_char(text, char):
    count = 0
    for c in text:
        if c == char:
            count += 1
    return count
for char in text:
    perc = 100 * count_char(text, char) / len(text)
    print("{0} - {1}%".format(char, round(perc, 2)))
0
Thanks, I'll try it 😉



