Difference between revisions of "Pig Latin Translator"

From WLCS
Line 12: Line 12:
 
'''Directions:'''
 
'''Directions:'''
 
# Your first task is to produce a function that takes one '''argument''', a string, and '''returns''' the portion of the word up to, but not including the first vowel. For example, if you sent 'banana' to your function, it should '''return''' 'b'. Sending 'Sibley' should return 'S', 'stream' should return 'str', and 'break' should return 'br'. Print out your working function and a sample run.
 
# Your first task is to produce a function that takes one '''argument''', a string, and '''returns''' the portion of the word up to, but not including the first vowel. For example, if you sent 'banana' to your function, it should '''return''' 'b'. Sending 'Sibley' should return 'S', 'stream' should return 'str', and 'break' should return 'br'. Print out your working function and a sample run.
 
 
# Using what you created from Step 1, write another function (or functions) that takes a single word as an argument and returns the word with the prefix and stem reversed.
 
# Using what you created from Step 1, write another function (or functions) that takes a single word as an argument and returns the word with the prefix and stem reversed.
 
 
# Modify the function from Step 2 to properly handle the 'ay' word ending, capital letters, and punctuation.
 
# Modify the function from Step 2 to properly handle the 'ay' word ending, capital letters, and punctuation.
  

Revision as of 14:29, 5 January 2009

Objective:

  • You will create a program that translates English to Pig Latin

Translation Rules:

  1. If a word has no letters, don't translate it.
  2. All punctuation should be preserved.
  3. If the word begins with a capital letter, then the translated word should too.
  4. Separate each word into two parts. The first part is called the prefix and extends from the beginning of the word up to, but not including, the first vowel. (The letter y will be considered a vowel.) The Rest of the word is called the stem.
  5. The Pig Latin text is formed by reversing the order of the prefix and stem and adding the letters ay to the end. For example, sandwich is composed of s + andwich + ay + . and would translate to andwichsay.
  6. If the word contains no consonents, let the prefix be empty and the word be the stem. The word ending should be yay instead of merely ay. For example, I would be Iyay.

Directions:

  1. Your first task is to produce a function that takes one argument, a string, and returns the portion of the word up to, but not including the first vowel. For example, if you sent 'banana' to your function, it should return 'b'. Sending 'Sibley' should return 'S', 'stream' should return 'str', and 'break' should return 'br'. Print out your working function and a sample run.
  2. Using what you created from Step 1, write another function (or functions) that takes a single word as an argument and returns the word with the prefix and stem reversed.
  3. Modify the function from Step 2 to properly handle the 'ay' word ending, capital letters, and punctuation.

Examples:

--> Stop
Opstay
--> No littering
Onay itteringlay
--> No shirts, no shoes, no service
Onay irtsshay, onay oesshay, onay ervicesay
--> No persons under 14 admitted
Onay ersonspay underay 14 admitteday
--> Hey buddy, get away from my car!
Eyhay uddybah, etgay awayyay omfray ymay arcay!