CSC207 - Lab 4
Strings of Text
Assigned September 9th 2 p.m.
Due September 14th 12 p.m.
Overview
In this lab we examine some of the methods for manipulating strings of text.
Materials
Step 1
Our first text for today comes from Lewis Carroll's poem "The Walrus and the Carpenter."
"The sun was shining on the sea,
Shining with all his might:
He did his very best to make
The billows smooth and bright--
And this was odd, because it was
The middle of the night."
As text is a major way of communicating with the user and storing information in a manner we can
easily understand, we will examine the built-in methods Python includes for manipulating these
strings.
Step 2
Now that you have some familiarity with string processing in Python, we will analyze a much
larger string from a file.
Download alice-chapter-one.txt
to your
working directory (the default where your files are saved).
Perform the following steps on the string, and record the results in
lab4_evaluation.txt
:
- Open this file through the interpreter and read in the data into a string.
This can be accomplished by typing
file = open("alice-chapter-one.txt", "r")
s = file.read()
- Convert this string to uppercase and record
the last 10 characters.
- Remove all spaces and carriage returns from the string.
- Find and record the percent of remaining characters that are the letter E.
- Find and record the percent of remaining characters that are the letter T.
- How many sentences are there in this text?
- Where is the third mention of the word "SHE"?
- What is the ordinal value of the middle character of the text?
What to Hand In
Log in to cs.centenary.edu
through either Secure FTP or WinSCP using your
cs login and password. Create a subdirectory from csc207
called lab4
. Write up your results from step 2 into a file called
lab4_evaluation.txt
and copy it into this directory.
You must hand in:
© Mark Goadrich 2008, Centenary College of Louisiana