Introduction: Piglatin Translator

About: I like to tinker with RaspberryPi and Arduino, fix or build just about anything, fly all kinds of R/C aircraft, and LOVE to race dirtbikes.

This is an easy to make, one word piglatin translator that I came across while taking Python at CodeCademy.com.

It is very easy to make and fun to play with.

As usual, I will be using Python 2. If you do not want to go through this entire Instrucable, I also have prewritten code below.

Step 1: Open Python

The first step is to open your choice of a Python 2 shell (I prefer IDLE Python 2). Now open a New File.

Step 2: The 'Piglatin Sufix'

The first line of code is simply just a variable that will hold the string "ay". I like to call this the 'Piglatin Sufix'.

pyg = 'ay'

Step 3: Raw_input

Next, we need to be able to type our word, preferably without modifying the code each time. For this we will use the function 'raw_input()' and make a variable called 'name' to hold it. Since we want the code to be user friendly, we will put a string inside the parentheses for it to print. Be sure to leave a space between the last letter and the apostrophe so nothing looks squished.

name = raw_input('Type your word ')

.

Step 4: The 'if' Function

Next, just for fun, we'll put an if function in the code. We will use the functions 'len()' and '.isalpha'. This means that if nothing is typed, or the type is not of letters, most of our code will be skipped and the computer will follow the code under 'else'.

if len(name) > 0 and name.isalpha:

Step 5: 'Word' Variable

Next we will create a variable that will hold the typed word in lower case letters.

word = name.lower()

Step 6: 'First Letter' Variable

Next we will create a variable to hold ONLY the first letter of the typed word.

first = word[0]

Step 7: Putting It All Together

Now it's time to put all of our newly established variables together to make our new word. But to do this we need to create another variable called 'new_word'.

new_word = word[1:] + first + pyg

Step 8: Print

Now we can print our new, translated word on the screen.


print new_word

Step 9: The 'else' Function

The else function is there just in case the type has something other than only letters in it.

else:

Step 10: If 'else' Happens

If the else function does take affect, we need something for the computer to do, just for fun. So we will tell the computer to print 'empty' on the screen

print 'empty'

Step 11: Finished!

Done! All that's left is to run the code, type your word, and hit enter. Now you can speak Piglatin fluently!

Step 12: Having Trouble?

Remember, puncuation, indentation, and spacing is very critical in coding. If you have to, download the prewritten code or look at each screenshot carefully. Happy coding!