10.9 yet another new exercise
Affects | Status | Importance | Assigned to | Milestone | |
---|---|---|---|---|---|
Practical Programming in Python |
Fix Released
|
Undecided
|
Unassigned |
Bug Description
Something simple with readlines like "
I Wandered Lonely As A Cloud by William Wordsworth
I wandered lonely as a cloud
That floats on high o'er vales and hills,
When all at once I saw a crowd,
A host, of golden daffodils;
Beside the lake, beneath the trees,
Fluttering and dancing in the breeze.
Continuous as the stars that shine
And twinkle on the milky way,
They stretched in never-ending line
Along the margin of a bay:
Ten thousand saw I at a glance,
Tossing their heads in sprightly dance.
The waves beside them danced, but they
Out-did the sparkling leaves in glee;
A poet could not be but gay,
In such a jocund company!
I gazed—and gazed—but little thought
What wealth the show to me had brought:
For oft, when on my couch I lie
In vacant or in pensive mood,
They flash upon that inward eye
Which is the bliss of solitude;
And then my heart with pleasure fills,
And dances with the daffodils.
Open a file and read the contents using readlines.
Count how many lines of the file contain some target string e.g. "daffodils" Print out the lines themselves, as they are found, then the count of the total number of lines containing the target string.
Modularise your code, so that the search string is an input to a function.
Extension: Count the number of blank lines in the file.
Actually added it to Chapter 11.