Skip to main content

10.11) Challenge 28 - Count Words And Lines


The file TheTyger_WilliamBlake.txt contains the poem The Tyger by William Blake.

  1. Write a program to count the numbers of lines and the number of words in the poem. There are a lot of different ways to do this.
  2. Advanced:

    • Only count the poem itself, not the title and author name
    • Don’t count blank lines
    • Don’t count punctuation

     

    You can use different ways of reading in the file, but you’ll also have to find different ways of counting the words and lines.

    Solution: count_words_lines.py

  3. Write the poem in a file, with each line preceded by the number of words on that line.
  4. Solution: count_words_lines_part2.py