Another stuck on my code (Check Yourself...Some More)


#1


https://www.codecademy.com/en/courses/python-beginner-2W5v7/0/5?curriculum_id=4f89dab3d788890003000096#

I now wrote this code:

print 'Welcome to the Pig Latin Translator!'

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


if len(original) > 0 and original.isalpha():
    print original
else: 
    print "empty"

And the output was:

Welcome to the Pig Latin Translator!
Enter a word: 89
89
empty
None

With the error message:

Oops, try again. It looks like your code prints original ("89") when original includes non-alphabetical characters.

Any errors in my code?


#2

delete this line...
print original


#3

It works perfectly. Thanks.

PS.

Can you tell me how this worked?


#4

Yeah,In problem we have to print original after we check if its non empty string and not a string containing numbers.
as you printed it earlier so string with numbers as characters also got printed!


#5

I see now. Thanks so much for helping me! :blush:


#6

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