PYGLATIN Pop Quiz!: Unable to Recognize Separate Strings


Hi! Why does my code recognizes and prints a single string (e.g. ‘Panama’), but is unable to recognize separate strings (such as ‘Panama City’) and prints, such case: “Empty”?

Here’s my code so far:

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"


pyg = 'ay'
#original prompts user to input a random word
original = raw_input('Enter a word:')
#then checks if it's a valid input: string values only, non-numeric
#otherwise, will print as 'empty'
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
  print 'empty'

Thanks in advance!


It is because of the space in the string ‘Panama City’, it is not a letter in the alphabet so ‘original.isalpha()’ evaluates to False.

1 Like