Python

When you ask a question, don’t forget to include a link to the exercise or project you’re dealing with!

If you want to have the best chances of getting a useful answer quickly, make sure you follow our guidelines about how to ask a good question. That way you’ll be helping everyone – helping people to answer your question and helping others who are stuck to find the question and answer! :slight_smile:
https://www.codecademy.com/courses/learn-python/lessons/pyglatin/exercises/pop-quiz

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"

On writing the input when I insert a space in between my input, the program gives the output as “Empty”. Why is that? Shouldn’t it print the word including space?

Hi there, and welcome to the forums! :slight_smile:

Presumably you’re getting empty back because one of your conditions evaluates to False.

You should take a look at the docs for the string method isalpha(). It tests for a very specific definition of “letter”, which a space does not meet, as we can easily test for:

>>> test = " "
>>> test.isalpha()
False

Given you’re building a pig latin translator, one assumes you’ll eventually expand your code to the point where you’ll deal with spaces in some fashion anyway. :slight_smile:

Also, you’ll notice that I’ve edited your post to correctly format your code. You should read this thread about how to do this, so you can format code correctly for any future questions. This preserves the whitespace and indenting, which is crucial in Python!

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