CPTR 124 Fundamentals of Programming
Problem Statement
In this lab you will work with Python strings.
It is said that teletype operators, after establishing a connection, would type the line:
THE QUICK BROWN FOX JUMPS OVER THE LAZY DOG
They used this line because it contains every letter of the alphabet. Write a program to test lines entered by the user to see if they have the same property.
When run, your program should request a line of input from the user and check to see if it contains all the letters of the English alphabet. A valid input line will consist of
- uppercase letters and spaces only, or
- a single period (.)
For each line entered, the program displays a report of the missing letters, if any. If the line used all the letters of the alphabet, the program prints "All letters present"; otherwise, it prints "Missing letters: " followed by the list of letters omitted from the line of text. The missing letters, if any, must appear in alphabetical order.
If the user supplies an invalid line, the program should print "Invalid line."
See the sample run below for examples of the exact presentation of the output.
Sample Run
The easiest way to keep track of the letters (one-character strings) in Python is to use a dictionary. Traverse the string, and keep track of the count of each letter. When finished traversing the string, check to see if each character is present in the dictionary. Report the missing letters.
Note: The character "A"
has an ASCII code 65,
"B"
is 66, etc. Python's ord
function
reveals the ASCII value of a character. You can convert an integer
ASCII code to a character using the chr
function.
With the chr
function, we can iterate over all the letters
of the alphabet as follows:
This simple program prints
You do not want to print out each letter, of course, but you can use a similar loop to query your dictionary to see if a letter is present (or maybe has a count greater than zero).
Check out
Your finished program will be evaluated for correctness and compliance. Once you have been checked out you may submit your code to eclass.e.southern.edu.