+ 1

Can soneone please explain this code to me?

I can't understand this code portion for char in "abcdefghijklmnopqrstuvwxyz": perc = 100 * count_char(text, char) / len(text) print("{0} - {1}%".format(char, round(perc, 2)))

7th Jun 2018, 12:44 PM
Mohammad Hasibul Haque
Mohammad Hasibul Haque - avatar
1 Resposta
+ 6
Without seeing text, it is a guess. But, likely. For each character in the alphabet (for statement), count how many times it is found in the text (count_char method call.) Generate the percentage of that character in the entire string (rest of the equation assigning to perc.) Print the character and it's percentage (print method call.)
7th Jun 2018, 3:11 PM
John Wells
John Wells - avatar