+ 4
I can't understand this code..
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
+ 3
Overview:
The program prints the percentage of frequency for each letter of the alphabet in a user-specified file.
The sequence is basically:
1. Prompt user for a file name.
2. Print frequency percentage for each letter of the alphabet.
count_char is named very clearly. It counts the number of occurrences of the specified character in the string called text.
count_char is used as part of the frequency percentage calculation.
Let me know if you have a more specific question about a specific part of the program.
+ 1
Already answered:
https://www.sololearn.com/Discuss/2377375/?ref=app