6/11 PygLatin prints original and empty


#1

Here is my input:

print 'Welcome to the Pig Latin Translator!'

name = raw_input("What is your name? ")
print name

original = raw_input("Enter a word please: ")

if len(original) > 0 and original.isalpha():
  print original
if len(original) > 0 and not original.isalpha():
  print "Excuse me?"
else:
  print "empty"

When I interact with the console, the output is this:
Welcome to the Pig Latin Translator!
What is your name? Ariel
Ariel
Enter a word please: cow
cow
empty

The only way I have been able to remedy this improper output of the word “empty” is by changing the else statement to another “if” statement:

if len(original) < 0:
  print "Empty"

But, I am frustrated because the lesson specifically asks me to use the “else” statement. I’m very confused as to why this output of both the original word and “empty” is occurring.

I know I have a couple additions to my code and I have seen some people claim that if you don’t follow the lesson exactly, you may not see the proper results. I have also tried running my code without the small additions, and it makes no difference.


#2

this:

if len(original) > 0 and not original.isalpha():

should be elif, by using a second if statement, you create undesired behaviour in your program.


#3

Thank you! That was the problem.


#4

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