텍스트 파일에서 평균 단어 길이 구하기 파이썬 기초

조회수 210회

Write a program that can calculate the average word length of any text file.

제가 만든 코드는

infileName = input("Enter file name: ")
infile = open(infileName, "r")

total_word_length = 0
total_words = 0

for line in infile:
    words = line.split()
    for word in words:
        total_word_length += len(word)
        total_words += 1

infile.close()

average_word_length = total_word_length / total_words
print(average_word_length)

이건데요...any file을 불러올때 저렇게 해도 되는건가요? spyder에 돌려봤는데 아예 답이 안나와서 여기에 물어봅니다

답변을 하려면 로그인이 필요합니다.

프로그래머스 커뮤니티는 개발자들을 위한 Q&A 서비스입니다. 로그인해야 답변을 작성하실 수 있습니다.

(ಠ_ಠ)
(ಠ‿ಠ)