편집 기록

편집 기록
  • 프로필 엽토군님의 편집
    날짜2023.08.08

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


    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에 돌려봤는데 아예 답이 안나와서 여기에 물어봅니다

  • 프로필 알 수 없는 사용자님의 편집
    날짜2023.08.07

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


    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에 돌려봤는데 아예 답이 안나와서 여기에 물어봅니다