Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def count_char(text, char):
- count = 0
- for c in text:
- if c == char:
- count += 1
- return count
- # This gives the users an option to enter the name of the file that they want opened
- # filename = input("Enter a filename: ")
- # This defines the filename
- filename = 'Sonnets.txt'
- with open(filename) as f:
- text = f.read()
- for char in "abcdefghijklmnopqrstuvwxyz":
- perc = 1 * count_char(text, char)
- print("{0} - {1}".format(char, round(perc, 2)))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement