Now let's take what we've learned so far and write a Pig Latin translator.
Pig Latin is a language game, where you move the first letter of the word to the end and add "ay." So "Python" becomes "ythonpay." To write a Pig Latin translator in Python, here are the steps we'll need to take:
- Ask the user to input a word in English.
- Make sure the user entered a valid word.
- Convert the word from English to Pig Latin.
- Display the translation result.
^^^^^^^
Instructions
I got the first line of code but im confused af
word = raw_input("Input a word in English")
bump for help :l
I'm not Kway, but I want to help again.
So, you've got the
word = raw_input(string)
- which is prompting the user for a string of bytes (so you know you'll get a string)
Then, I presume when it tells you to check it's a valid word, you'll want to make sure it's made out of alphabetical characters.
But you'd need to use regex, and until it clicks, regex is really confusing. By all means, try it out, it's very useful!
So, for now, you could just make sure it's not an empty string, like so:
if word: # 'if word' is essentially 'if word is True'
# continue with code
else:
# prompt for input again
Then do some string slicing and concatenation of 'word', like so:
>>> word = "welcome"
>>> changed_word = word[1:] + word[0:1] + "ay"
(Hope you understand what's going on there, just say if you don't. )
And then, the most complicated step:
print(changed_word)
Hope this helped!