Member-only story
Pig latin is a game that we played as children. The idea is to take the first letter of a word, move it to the last position, and add the letters ‘ay’ to it.
Making a pig latin generator is a good way to learn about while loops. In Python, a while loop is a control flow statement that allows you to repeatedly execute a block of code as long as a certain condition is true. The while loop keeps iterating until the condition becomes false.
The pig latin generator is comprised of a while loop that will continue to run indefinitely. The psuedocode for the generator is as follows:-
- The user will be prompted to enter a word.
- The while loop will continue to run as long as the word entered is not ‘quit’, and at which time a message will come up saying the program has ended and will break out of the for loop.
- If the word entered is not all alphabetical characters, the user will be given a message saying the word must be all letters in English, and the program will continue to the beginning of the loop.
- When the user enters a word in English, the first letter of the word (position 0) will be moved to the last position and the letters ‘ay’ will be added to it.