How do you add spaces to your PygLatin translator?


This is my final code for the PygLatin translantor. I followed all of the computer directions, and added some tweaks so it works with more words, but I cant get it to work with spaces, so I can do a sentence of PygLatin. I know I would need to erase the isalpha function, but after that I have no idea of what to do so it stops at a space and starts again with the next word in a sentence. Can somebody please help?

def is_consonant(nonvowel):
    all_consonants = 'bcdfghjklmpqrstvwxyz'
    return nonvowel in all_consonants
def is_vowel(char):
    all_vowels = 'aeiou'
    return char in all_vowels
vowel = 'way'
pyg = 'ay'
original = raw_input('Enter one word:')
if len(original) > 0 and original.isalpha():
     word = original
     word = word.lower()    
     first = word[0]
     new_word = word + first + pyg
     new_word = new_word[1:len(new_word)]
     combo_word = word[2:] + word[0:2] + pyg
     vowel_word = word + vowel
     if (is_consonant(word[0:1])) and (is_consonant(word[1:2])):
         print combo_word
     elif (is_vowel(word[0])):
         print vowel_word
         print new_word
     print 'invalid word'


i would break down the sentence in a list containing each word, lets say the user enters hello world i would make the string into a list:


you can do this manually (using loops), or use built in methods like .split()

this would be a good start


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