This lab used conditionals and control flow. This lab allowed me to create a program that would change a word into Pig Latin.





In this screenshot, I used the “raw_input” keyword to prompt the user to enter a word. I assign this to a variable named original so whatever the user inputted would be stored as in the variable original.


In this screenshot, I used an if statement to give the code a condition. The keyword “len” counts the amount of letters in a string (this includes white space). If the length of the string is greater than 0, then it would print the original string. If the length of the string is less then 0, the program would print the string ’empty’ since the user probably did not enter in anything.


I added a second condition in my if statement by using the “and” keyword which means the input has to qualify for both terms. I used the function .isalpha() to make sure the string only contains letters, and kept the rest of the code the same.


This portion is straightforward, we assigned the string “ay” to the variable pyg,


Here, I created a new variable named “word”. I assigned it to original.lower(), this means that the string that was inputted by the user will be transformed into lowercase. Then created a new variable named “first” and assigned it to word[0]. word[0] means that it will take the first letter of the string.


I created a new variable named “new_word” then added the variables word, first, and pyg so that it would bind fragments of string together.


In this screenshot, you assign new_word to new_word[1:len(new_word)]. [1:len(new_word)] splices the string and removes the 1st letter from the string.


This is the result from the script.