Lab Assignment #3

PIG LATIN


Description
In this assignment, I will follow the steps on how to build a Pig Latin translator from Codecademy’s Python section. Pig Latin is a pseudo-language that is used by English-speakers who wants to disguise their words from non-Pig Latin speakers. The rule is to take the first consonant of an English word, move it to the end of the word and use the suffixes ‘ay’. If the word begins with a vowel, add ‘way’ at the end. For example, Pig becomes igpay, banana becomes ananabay, and aardvark becomes aardvarkway. Below are the instructions I followed in Codecademy.


Break It Down
1. Ask the user to input a word in English.
2. make sure the user entered a valid word.
3. Convert the word from English to Pig Latin.
4. Display the translation result.

Break It Down


Ahoy! (Or Should I Say Ahoyay!)
Print the phrase “Pig Latin” on the screen.

Ahoy! (or Should I Say Ahoyay!)


Input!
1. On line 4, use raw_input(“enter a word:”) to ask the user to enter a word. Save the results of raw_input() in a variable called original.
2. Click save & submit code.
3. Type a word in the console window and press enter.

Input!


Check Yourself!
1. Add an if statement that checks that len(original) is greater than zero. Don’t forget the : at the end of the if statement!
2. If the string actually has some characters in it, print the user’s word.
3. Otherwise (i.e. an else: statement), print “empty”.

Check Yourself!


Check Yourself… Some More
Use and to add a second condition to your if statement. In addition to your existing check that the string contains characters, you should also use .isalpha() to make sure that it only contains letters.
Don’t forget to keep the colon at the end of the if statement.

Check Yourself Some More


Pop Quiz!
Take some time to test your current code. Try some inputs that should pass and that should fail. Enter some strings that contain non-alphabetical characters and an empty string.

Pop Quiz!


Ay B C
Create a variable named pyg and set it equal to the suffix ‘ay’.

Ay B C


Word Up
Inside your if statement:
1. Create a new variable called word that holds the .lower()-case conversion of original.
2. Create a new variable called first that holds word[0], the first letter of word.

Word Up


Move It On Back
On a new line after where you created the first variable:
Create a new variable called new_word and set it equal to the concatenation of word, first, and pyg.

Move it on Back


Ending Up
Set new_word equal to the slice from the first index all the way to the end of new_word. Use [1:len(new_word)] to do this.

Ending Up


Testing, Testing, Is This Thing On?

Testing, Testing, is This Thing On


CODE
pyg = ‘ay’
original = raw_input(‘Enter a word: ‘)
word = original.lower()
first = word[0]
new_word = word + first + pyg
new_word = new_word[1:len(new_word)]
if len(original) > 0 and original.isalpha():
print new_word
else:
print ’empty’