PythonHolic
[python] txt 파일 내의 영어 알파벳 갯수 새기 본문
def main():
#list for print
temp = ['a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p'
,'q','r','s','t','u','v','w','x','y','z']
count =0
while True:
try:
file = input("Enter a filename : ").strip()
file = open(file,'r')
break
except:
print("파일명이 존재하지 않습니다")
counts = []
for i in range(26):
counts.append(0)
for j in file:
countLetters(j.lower(),counts)
while count<=25:
for i in counts:
print("{} : ".format(count+1),temp[count],"appears {} times".format(i))
count+=1
def countLetters(line,counts):
for k in line:
if k.isalpha() == True:
counts[ord(k)-97]+=1
main()
'파이썬 과제 도와주기 일지' 카테고리의 다른 글
[python] 대수학자 minje-Kim이 만든 minjeK수열 문제 (0) | 2020.06.25 |
---|---|
[python] 리스트 안에 있는 단어중 가장 긴 단어와 짧은 단어 찾기 (1) | 2020.06.25 |
[python] 주사위를 던져 높은숫자가 나온사람이 이기도록 하기 (0) | 2020.06.25 |
[python] 2명에서 하는 가위바위보에서 나올수 있는 모든 경우의 수 (0) | 2020.06.25 |
[python] math 모듈을 통한 최대공배수 구하기 (0) | 2020.06.25 |
Comments