CSC207 - Lab 4
Strings of Text


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:

  1. 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()
    

  2. Convert this string to uppercase and record the last 10 characters.
  3. Remove all spaces and carriage returns from the string.
  4. Find and record the percent of remaining characters that are the letter E.
  5. Find and record the percent of remaining characters that are the letter T.
  6. How many sentences are there in this text?
  7. Where is the third mention of the word "SHE"?
  8. What is the ordinal value of the middle character of the text?

What to Hand In

Write up the answers to the above questions for Part 1 and Part 2 in a Google Doc, and share this with me.
© Mark Goadrich 2010, Centenary College of Louisiana