CS 8, Spring 2017

Programming Project 2

Due: Sunday, May 14, 11:59pm
Worth: 100 (project) points

     
  • Create a new file named project2.py in whatever folder you choose to work on this project (presumably ~/cs8/p2/). Add a comment at the beginning that includes your name (and your partner's name if you are working with another student) and the date the program is written.
  • Your solutions to all parts of this project must be typed into project2.py. It is okay to write helper functions in addition to the three required functions if you want.
  1. (25 points) Write a function to determine if a sentence is a "pangram" or not.
    • A pangram, also known as a "holoalphabetic sentence" is a sentence that contains every letter of the alphabet. Here are some example pangrams:
      • The quick brown fox jumps over the lazy dog.
      • A very bad quack might jinx zippy fowls.
      • Pack my box with five dozen liquor jugs.
      As you can see, it does not matter if the letters are upper or lower case, and of course spaces and punctuation are ignored.
    • The function header must exactly match the following:
      def isPangram(sentence):
    • Return (don't print) True if the sentence is a pangram, or return False if it is not.
    • Test your function in the Python shell. Here are sample tests of our solution:
      >>> from project2 import isPangram
      >>> isPangram("Quick brown fox jumps over the lazy dog.")
      True
      >>> isPangram("Quick brown fox trips over the sly dog.")
      False
      >>> answer = isPangram("abcdefghijklmnopqrstuvwxyz")
      >>> print(answer)  # note: depends on returned value 
      True
  2. (25 points) Write a function to determine if some text forms a "palindrome" or not.
    • A palindrome is a word or phrase that is spelled the same forward and backward. Here are some sample palindromes:
      • A man, a plan, a canal: Panama
      • Madam, I'm Adam.
      • Yreka Bakery
      Again, it does not matter if the letters are upper or lower case, and spaces and punctuation are ignored.
    • The function header must exactly match the following:
      def isPalindrome(text):
    • Return (don't print) True if the text forms a palindrome, or return False if it does not.
    • Here are sample tests of our solution in the Python shell:
      >>> from project2 import isPalindrome
      >>> isPalindrome("Madam, I'm Adam.")
      True
      >>> isPalindrome("abcda")
      False
      >>> answer = isPalindrome('Ada')
      >>> print(answer)  # note: depends on returned value
      True
  3. (50 total for parts a and b) Write a function that translates English language text to "Pig Latin" according to the following rules for translating one word:
    • If the word begins with a vowel (a,e,i,o,u), then it is simply translated by appending 'way' to the end of it. As examples, 'act' becomes 'actway' and 'old' becomes 'oldway' and so on.
    • If the word does not begin with a vowel (it starts with a consonant), then it is translated by moving all consonant letters up to the first vowel to the end of the word with 'ay' appended to the very end. As examples, 'gasp' becomes 'aspgay' and 'school' becomes 'oolschay' and so on. This rule also applies when the word has no vowels at all - in that case, 'ay' is simply appended.
      Special cases:
      • The letter 'y' is counted as a vowel in this context (when a word begins with a consonant). Examples: 'system' becomes 'ystemsay' and 'crystal' becomes 'ystalcray' and so on.
      • The letter 'u' is counted as a consonant when it follows the letter 'q' in a word, so 'queen' becomes 'eenquay' and 'square' becomes 'aresquay' for examples.
    • Capitalization is properly maintained. Words that are all capital letters are translated to all capital letters ('IBM' becomes 'IBMWAY' and 'CRUMB' becomes 'UMBCRAY'). Also, words that are properly capitalized are translated with proper capitalization ('Apple' becomes 'Appleway' and 'Mark' becomes 'Arkmay')

    We suggest you solve this problem in two parts, and the points will be allocated accordingly:

    1. (25 points) Get the function working for just one word. That is, full credit for this part is earned by translating text that consists of nothing except alphabetic characters. Return (don't print) the translated text as a string. See (and be sure to match) the first few sample runs below.
    2. (25 points) Improve the function so that it works with text that consists of any characters, and presumably multiple words. Translate each word separately. A word is defined as any consecutive sequence of alphabetic letters, and they may be separated by any sequence of non-letter characters. All non-letter characters should just be copied to the Pig Latin translation.

    The function header must exactly match the following:

    def pigLatin(text):

    Here are some sample runs of our pigLatin solution:

    >>> from project2 import pigLatin
    >>> pigLatin('banana')
    'ananabay'
    >>> p = pigLatin("Apple")
    >>> print(p)  # note: depends on returned value of p
    Appleway
    >>> pigLatin('Square')
    'Aresquay'
    >>> pigLatin('My hovercraft is full of eels.')
    'Ymay overcrafthay isway ullfay ofway eelsway.'
    >>> pigLatin('FDA says: "Three squares is the way to go!"')
    'AFDAY ayssay: "Eethray aressquay isway ethay ayway otay ogay!"'

  4. Go to CSIL (in person unless you can manage this step remotely without any assistance from us). Open a terminal window, cd to the same directory as your source code file, then type the following (careful - turning in to uppercase P-two, P2, at class account cs8c):
    turnin P2@cs8c project2.py
    If you are working with a partner, be sure that both partners names are in a comment at the top of the file.

Updated 5/1/2017, by C. Michael Costanzo