Pop Quiz!


#1

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
else:
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.


#2

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?


#3

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.


#4

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


#5

Ooh the loop is a good alternative, thank you!


#6

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


#7

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