Assignment 14 — web access
Due Saturday, September 26
Problem ccw.py
- Gets two inputs
- Name of a web file from the class web folder http://www.cs.virginia.edu/cs1112/datasets/text/
- Character of interest
- Produces three outputs
- Number of characters in the web file,
- Number of times the character of interest occurs in the web file, the
- Number of words in the web file.
Requirement
- Only output what is requested.
Three program runs
Enter name of web file: roman
Enter single character: v
14 1 7
Enter name of web file: macbeth
Enter single character: u
416 35 69
Enter name of web file: tom-sawyer
Enter single character: z
368697 151 71053
Suggested algorithm
- Import Python functionality for reading a web file.
- Define repository for text files of interest.
- Input name of web file.
- Clean up name — strip it.
- Input character of interest.
- Define the link to the web file.
- Get a connection to stream data from the web file
- Read the stream to get the encoded contents of the page
- Decode the page into plain text
- Compute the length of the web file.
- Count the number of times the character of interest occurs in the web file.
- Convert the text into a list of words.
- Compute the length of the list.
- Print the results.
© 2020 Jim Cohoon | Resources from previous semesters are available. |