Pop Quiz!


Hello, this is my code:

print ‘Welcome to the Pig Latin Translator!’

Start coding here!

original = raw_input("Enter a word: ")
if len(original) > 0 and original.isalpha():
print original
print “empty”

It works, however when my input contains a space at the beginning it gives back “empty”. I guess this means a space doesn’t count as a letter from the alphabet, but I still want my function to give back my input no matter how many spaces it contains. How do I fix this? cheers.


this program isn’t designed to handle more then one word, if you want to handle more then word, how should the translation be handled? Should each word be transformed to pyglatin?


I do not want to insert more words. I just want it to work when I’m including spaces because that could be a mistake that happens often.


it makes your program more complicated, is that worth it? you could check if first character is space and the rest is alpha:

if original[0:1] == " " and original[1:].isalpha()

but then you also need to check if original is alpha, so it complicates your program. You could consider to inform the user not to enter spaces? And use a loop to allow the user to input multiple times


Ooh the loop is a good alternative, thank you!


the alternative is to use a regular expression. This will allow you to verify [a-z]+ and the space at beginning (or not)


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