PYGLATIN Pop Quiz!: Unable to Recognize Separate Strings

Link: https://www.codecademy.com/courses/learn-python/lessons/pyglatin/exercises/pop-quiz?action=resume_content_item

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
else:
  print "Empty"

FINAL CODE

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
else:
  print 'empty'

Thanks in advance!

Hello,

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