Guest User

Untitled

a guest
May 22nd, 2018
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.02 KB | None | 0 0
  1. #program by David Weinberger
  2. ###############Functions###############
  3. def countLetterFileName(character,file):
  4. #returns value in for main function
  5. finalvalue = countLetterOpenFile(character, open(file))
  6. return finalvalue
  7.  
  8. def countLetterOpenFile(c, file):
  9. #Opens file
  10. value = 0
  11. for line in file:
  12. line = line.strip()
  13. d = countLetterword(c, line)
  14. value +=d
  15. return value
  16.  
  17. def countLetterword(c, line):
  18. #Counts number of times a character shows up
  19. value = 0
  20. for char in line:
  21. if char == c:
  22. value +=1
  23. return value
  24.  
  25. def main():
  26. #Primary function, takes a letter and counts the number of times it is in a document
  27. character = input("""Enter a Letter Please: """)
  28. filename = input("""Enter File Name: """)
  29. total = countLetterOpenFile(character,filename)
  30. print("Total count of " , character , " = " , total)
  31.  
  32.  
  33. ###############Calling Functions###############
  34. main()
  35.  
  36. input("press enter to end")
Add Comment
Please, Sign In to add comment