Playing With Strings

Thomas J. Kennedy

Contents:

1 The Problem

If you are anything like me… you often end up teaching a friend’s child, parent’s friend’s child, younger cousin, or neighbor’s child something about…

(I am looking forward to teaching these topics to my daughter in a couple years.)

1.1 Brainstorming

Suppose that we need to help our young charge (primary school age) prepare for an English quiz. Our charge is learning the basics of sentence structure. They have asked you…

Is it possible to have the computer check my sentences?

Of course… we know that we can write a Python program, and, more importantly, use this as the start of both an English and Computer Science combo lesson! (See… there is a reason we are not using something along the lines of Grammarly.)

1.2 Our Solution

Our goal is twofold…

  1. Help our young charge with their grammar skills

  2. Set up a Python lesson

At the end of the day… we want our program to do the following…

  1. Check that the first letter of a sentence is capitalized.

  2. Check that a sentence ends with a period, question mark, or exclamation point.

  3. Check for quotes, commas, semicolons, colons, dashes, and ellipses.

    Our young charge has started raiding their parents’ bookshelves… and Isaac Asimov and J.R.R. Tolkien are grammitical artists.

    If these symbols show up in a sentence we want to remind our young charge to practice the not fun stuff first.

1.3 Input

This subsection will describe the input content, format, and overall structure.

Input to this program will be interactive (i.e., a prompt will be displayed and the program will wait for keyboard input). User input will be a sentence.

1.4 Output

A single execution of the program will be similiar to…

Enter a sentence: Hello, my name is Tom.

Analysis:

  1. Sentence starts with 'H' (captital letter)
  2. Sentence ends with a/an '.' (punctuation)
  3. Sentence does not include *advanced* puntuation 

Would you like to check another sentence? (yes/no): no

2 Your Tasks

You work will focus on three functions. You will need to mkae use of Python’s built-in str complete functions to…

  1. Check that the first letter of a sentence is capitalized.

    def first_letter_is_capitalized(sentence: str) -> bool:
        """
        T.B.W.
        """
    
  2. Check that a sentence ends with a period, question mark, or exclamation point.

    def ends_with_punctuation(sentence: str) -> bool:
        """
        T.B.W.
        """
    
  3. Check for quotes, commas, semicolons, colons, dashes, and ellipses.

    def includes_advanced_punctuation(sentence: str) -> bool:
        """
        T.B.W.
        """
    
    

You will notice that each function has a placeholder for pydoc documentation…

    """
    T.B.W.
    """

3 Mechanics

You can run the main program with…

python3.11 check_sentence.py

The test code can be run with…

python3.11 -m pytest -v tests

4 Files

There are three (3) files in this assignment:

You will be working in examine_sentence.py. Do not modify the other files.

You can access the starting files on GitHub. You may either clone the starting repository (through Git) or download a zip file.

5 Grading

Your grade will be based on the following criteria…

6 Submitting

You will submit your completed copy of examine_sentence.py as a file upload through Canvas.

Do not alter any of the other source code files, nor change the module interface.