Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #在原始檔案中加入了小寫j與大小寫Z,z , 以解決for迴圈的bug
- import string
- inf = "hw1_5.txt"
- outf = "hw1_5out.txt"
- def main():
- infile = open(inf,"r")
- outfile = open(outf,"w")
- total = {}
- for line in infile.readlines():
- outfile.write(line)
- for ch in line:
- if ch in total:
- total[ch] = total[ch] + 1
- else:
- total[ch] = 1
- infile.close()
- outfile.close()
- combine = {}
- totalch = 0
- for ch in string.ascii_uppercase:
- combine[ch] = total[ch] + total[ch.lower()]
- totalch = totalch + combine[ch]
- print(ch,combine[ch])
- print("There are totally", totalch-3 , "letters.")
- main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement