0

Can anyone explain the part where "if c==char:" What is char? I check char is Z.

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)))

18th Nov 2019, 3:05 AM
kengxiong
2 odpowiedzi
+ 6
text is string and hence for c in text means c is character...so, c being compared to char means char is character which is input to function. this means function find howmnay times char is present in entire text
18th Nov 2019, 3:11 AM
Ketan Lalcheta
Ketan Lalcheta - avatar
+ 4
Please add Python to your question tags 👍
18th Nov 2019, 4:28 AM
Ipang