0

i need my pyglatin translator to return 'ellohay, orldway.' when i input 'Hello, world.' however i a unsure of what code needs to be inserted t make it do what i want. this is what i have so far;

pyg = 'ay'

input = raw_input("Please enter a sentence:")
print input

if len(input) > 0:
    input = input.lower()
    phrase = input.split( )
    pyg_words = []

    for item in phrase:
        if item.isalpha():
        first = item[0]
            item = item[1:] + first + pyg
             pyg_words.append(item)
    print ' '.join(pyg_words)
Michael Berkowski
  • 267,341
  • 46
  • 444
  • 390
  • Check out http://stackoverflow.com/questions/15400008/python-pig-latin-converter, it includes a few methods for completing this. – LinkBerest Mar 14 '15 at 02:07

1 Answers1

0

One way is to write your code like this:

pyg = 'ay'
input = raw_input("Please enter a sentence:")
print input

    if len(input) > 0 and input.isalpha:
    input = input.lower()
    phrase = input.split( )
    pyg_words = []

        for item in phrase:
            if item.isalpha():
                first = item[0]
                item = item[1:] + first + pyg
                pyg_words.append(item)
            print ' '.join(pyg_words)
            else:
                print 'Please enter a sentence that only contains letters.'

input.isalpha() checks if the input contains only alphanumeric characters (or only letters).

12PAIN21
  • 1
  • 1