Advertisement
Guest User

Untitled

a guest
Sep 18th, 2019
100
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.47 KB | None | 0 0
  1. def count_char(text, char):
  2. count = 0
  3. for c in text:
  4. if c == char:
  5. count += 1
  6. return count
  7.  
  8.  
  9. # This gives the users an option to enter the name of the file that they want opened
  10. # filename = input("Enter a filename: ")
  11.  
  12. # This defines the filename
  13. filename = 'Sonnets.txt'
  14. with open(filename) as f:
  15. text = f.read()
  16.  
  17. for char in "abcdefghijklmnopqrstuvwxyz":
  18. perc = 1 * count_char(text, char)
  19. print("{0} - {1}".format(char, round(perc, 2)))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement