PygLatin 10/11


#1

Help me please... I've been stuck here for weeks, i keep getting Oops, new_word should be a string
while actually it is string, and i've also coded it on Visual Studio and it runs very well. What did i do wrong?
:frowning:

    pyg = 'ay'

original = raw_input('Enter a word:')
word = str
new_word = str

def pig_translator():
    if len(original) > 0 and original.isalpha():
        word = original.lower()
        first = word[0]
        new_word = word + first + pyg
        new_word = new_word[1:len(new_word)]
        print new_word
        return True
    else:
        print 'empty'
    
print pig_translator()

the result if i put DAVID is avidday. which is right.. but why i keep getting the error................


#2

I'm going to post my working code for you, as I know these things on CA can get glitchy at times & seem to only want to accept a predetermined answer. No need for you to stay stuck on it for weeks when you've clearly got the concept down. Hope this helps!

original = raw_input('Enter a word:')

if len(original) > 0 and original.isalpha():
    pyg = 'ay'
    word = original.lower()
    first = word[0]
    new_word = word+first+pyg
    new_word = new_word[1:len(new_word)]
    print new_word
else:
    print 'empty'

#3

You did alot more than you needed
you dont have to make a variable equal to str. also why do you have 'def pig_translator():' in there along with a not needed 'return True' statement, also dont need the last 'print pig_translator()' either

++++++++
your code
++++++++

pyg = 'ay'

original = raw_input('Enter a word:')
word = str
new_word = str

def pig_translator():

if len(original) > 0 and original.isalpha():
    word = original.lower()
    first = word[0]
    new_word = word + first + pyg
    new_word = new_word[1:len(new_word)]
    print new_word
    return True
else:
    print 'empty'

print pig_translator()

++++++++++++
your fixed code
++++++++++++

pyg = 'ay'

original = raw_input('Enter a word:')

if len(original) > 0 and original.isalpha():

word = original.lower()
first = word[0]
new_word = word + first + pyg
new_word = new_word[1:len(new_word)]
print new_word

else:

print 'empty'

#4

Thank you so much. This helped me a lot !! :grinning:


#5

it works! oh thank you so much! your comment are very kind btw!
thanks agaiiiin!


#6

Thanks so much for the explanation!
I print out the pig_translator() because i want to see the flow to check whether or not i get all the process right.

Nonetheless, thanks so much!


#7

@ryebread4

If your going to get rid of the extra stuff let's get rid of the variables we dont need too.

EXAMPLE:

def pig_latin():
    word = raw_input("Enter a word:").lower()
    if (word and word.isalpha()):
        return word[1:] + word[0] + 'ay'
    else:
        return 'Empty'

#8

very useful thank you


#9

Legend, this is so satisfying. Thanks for helping me learn!!! :sunglasses:


#10

Thanks mesimoo you are thee besstststststst