For people who are stuck here is my code + a decoder i added


#1

Here is my working code plus a decoder i added at the end:

this is what is needed for the corse

pyg = 'ay'
original = raw_input('Enter a word you want to code:')

if len(original) > 0 and original.isalpha():
#sets word to lower case
word = original.lower()
#adds first letter to the end
first = word[0]
#putts word together
new_word= word+first+pyg
#removes first letter
new_word = new_word[1:len(new_word)]
print 'The coded word is:'
print " "+new_word
else:
print 'empty'
#this is just adds a little white space in the output
print
print
print
print

decoder starts here

word_uncode= raw_input('Enter a word you want to decode:')

if len(word_uncode) >0 and word_uncode.isalpha():
#Check to see if code ends in 'ay'
check = word_uncode
check=check[-2:]
if check ==pyg:
#removes 'ay' from the end of the word
uncode= word_uncode[0:-2]
#grabs last letter
last = uncode[-1]
#Puts the word together
uncode = last+uncode[0:-1]
print 'The decoded Word is:'
print " "+uncode
else:
print 'Error: Your word is not in Pig Latin'

else:
print 'Invalid Input'

Tell me what you think?


#2

first of all, put your code inside the <./> button so we can read it.
second, it is not allowed to just post answers. https://discuss.codecademy.com/guidelines
"Please do not just post answers, or ask for them."
I see that you are trying to help people, but maybe provide more of an explanation/snippets so people can't just cheat?


#3

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.