0
What does it mean the last line?
Hello If it is not too much trouble, can someone explain to me in a general way what each line of this code means ?, but specifically the last one def count_char(text, char): count = 0 for c in text: if c == char: count += 1 return count filename = input("Enter a filename: ") with open(filename) as f: text = f.read() for char in "abcdefghijklmnopqrstuvwxyz": perc = 100 * count_char(text, char) / len(text) print("{0} - {1}%".format(char, round(perc, 2)))
2 Answers
+ 4
That's a string formatting.
{0} and {1} will be replaced against arguments 1 and 2 in the parentheses.
First argument is char, the second the value perc, rounded to two decimal places.