Homework #4

Due: February 15, 2012Points: 100

As for all earlier assignments, please put refinements for all your programs into one file called “refinements.txt” or “refinements.pdf”, and error journal entries for all your programs into one file called “errors.txt” or “errors.pdf”.

In the example outputs, what your program outputs is in typewriter font, what the user types is in italicized typewriter font, and the user typing “enter” or “return” is represented by the character “↵”. You don’t need to change the font, use italics, or show the “↵” in your output.

  1. (60 points) Write a program that reads a line of input and prints “Palindrome” if the input is a palindrome, and “Not a palindrome” if it is not. Your program should continue reading lines of input until the user enters a line with no characters. Write this program in three steps:
    1. (30 points) Your program may assume that the user will enter only lower-case letters and digits. No spaces, upper-case letters, or punctuation will occur. Example output is:
      Please enter your string: helloworld
      Not a palindrome
      Please enter your string: abcdedcba
      Palindrome
      Submit: Please turn in your program in the file “pala.py”.
    2. (15 points) Your program must now handle upper and lower case letters. For purposes of a palindrome, treat them as the same; that is, “A” and “a” match both “A” and “a”. You may assume that the user will not enter any non-letter non-digits. For example:
      Please enter your string: HeLlOwOrlD
      Not a palindrome
      Please enter your string: AbCdEeDcBa
      Palindrome
      Please enter your string: AmanaplanacanalPanama
      Palindrome
      Submit: Please turn in your program in the file “palb.py&trdquo;.
    3. (15 points) In addition to upper and lower case, your program must now handle non-letter non- digits such as punctuation. Specifically, it is to exclude them from the determination of whether the input is a palindrome. For example:
      Please enter your string: hello, world!
      Not a palindrome
      Please enter your string: A man, a plan, a canal--Panama!
      Palindrome
      Submit: Please turn in your program in the file “palc.py”.
  2. (40 points) Write a program that reads a line of input and prints the number of vowels, consonants, digits and other characters in the input. (For this exercise, the vowels are “a”, “e”, “i”, “o”, and “u”, in either upper-case or lower-case. All other letters are consonants.) The output should look like:
    Enter your line: gleep sn0rk!
    'gleep sn0rk!' has 1 digit, 2 vowels, 7 consonants, and 2 other characters.
    Your program is to read one input, produce the output, and stop. Notice that the program prints the input in single quotes, and if there is only one digit, vowel, consonant, or other character, it prints the singular of the word “digit”, “vowel”, “consonant”, or “character” as appropriate. As another two examples:
    Enter your line: 3er,
    '3er,' has 1 digit, 1 vowel, 1 consonant, and 1 other character.
     
    Enter your line: 3er,3ER,
    '3er,3ER,' has 2 digits, 2 vowels, 2 consonants, and 2 other characters.
    Submit: Please turn in your program in the file “count.py”.

A PDF version is available here.
ECS 10, Basic Concepts of Computing
Winter Quarter 2012
\end{document}