Advertisement
Guest User

Untitled

a guest
Mar 24th, 2019
94
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.73 KB | None | 0 0
  1. #在原始檔案中加入了小寫j與大小寫Z,z , 以解決for迴圈的bug
  2. import string
  3.  
  4. inf = "hw1_5.txt"
  5. outf = "hw1_5out.txt"
  6.  
  7. def main():
  8. infile = open(inf,"r")
  9. outfile = open(outf,"w")
  10. total = {}
  11. for line in infile.readlines():
  12. outfile.write(line)
  13. for ch in line:
  14. if ch in total:
  15. total[ch] = total[ch] + 1
  16. else:
  17. total[ch] = 1
  18. infile.close()
  19. outfile.close()
  20.  
  21. combine = {}
  22. totalch = 0
  23. for ch in string.ascii_uppercase:
  24. combine[ch] = total[ch] + total[ch.lower()]
  25. totalch = totalch + combine[ch]
  26. print(ch,combine[ch])
  27. print("There are totally", totalch-3 , "letters.")
  28. main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement