Lab #4: PygLatin

In today’s lab, we messed with conditions more in depth, about the logic operators and comparators. We used them along with the if and elif statements which we touched on an earlier lab. As an end result, we were able to create a translator to turn words into pig latin.

First we created a user input for the user to be able to type any word and have the program save it in a variable for later use.Capture

After capturing the input, we tested if it was a word, rather than a blank word. To do this “len” was used to measure the amount of characters there were in the word, if it equaled zero then it would print empty else it would print the original word.Capture2

It wasn’t enough because someone can put symbols or numbers inside that could mess up the whole idea of translating to pig latin so we had to test if it was only alphabetical letters only.Capture3

Forgot to make sure that it won’t take any blank input.Capture4

Now we created a variable that holds what needs to be added to the end of the word, in this case “ay”. In the if statement, all characters in the word was lower-cased and saved into a variable called word. Also the first character of the word was taken and saved as well in first.Capture5

Next we combined them all to make a new word and saved them in a new variable called new_word.Capture6

But pig latin doesn’t work that way, the first letter of the word must move to the end of the word and not remain as the first character in the word, so we have to slice the first character off , then save it again in the same variable.Capture7

Finally to print the final product.Capture8