CS 111: Introduction to Computer Science

Menus, functions, and strings

Hand in via Moodle as menu.py.

Goals

The program

For this assignment, you'll get the opportunity to apply your knowledge of loops, conditionals, and functions to create a small menu-driven program that will enable your user to play with strings. You may wish to use some of Python string methods.

When a person executes your program, your program should ask the person to enter a string. Next, the following menu should appear:

A. How many characters are in the string? B. How many letters are in the string? C. How many consonants are in the string? D. Is the string a palindrome? E. What is the Caesar Cipher (shift 3) of the string? Q. Quit Your choice:

Once the person makes a choice, the program should perform the requested task. If the person chooses Q, then the program should terminate. Otherwise, the process should continue--ask the user for another string, print the menu, get a choice, etc.

In options B and C, you may assume that the user's text will consist of only Latin-alphabet letters, spaces, and miscellaneous punctuation. So you don't have to worry about what constitutes a consonant in the Cyrillic or Greek alphabets.

For the purposes of this assignment, you may assume that a string is a palindrome only if it is exactly the reverse of itself. Thus, "rats live on no evil star" will be a palindrome, but "sit on a potato pan, Otis." will not. (If you wish to write a more sophisticated palindrome tester that ignores punctuation, capitalization, and spacing, feel free to do so. It won't earn you extra points, but I bet you'll have fun doing it.)

Also, let's pretend that the letters y and w are never vowels.

To get started, save and run this program: menu.py. This program illustrates a simple menu-and-response structure that you can adapt for this assignment.

Start early, ask questions, and have fun!