.isalpha() not working?


#1

This code doesn't work if I enter letters and numbers. Any idea what is wrong?

print 'Welcome to the Pig Latin Translator!'

Start coding here!

original = raw_input("enter a word:")
print original
if len(original) > 0 and original.isalpha():
print original
else:
print "empty"

`


#2

original = raw_input("enter a word:")
     print original #You dont need this one
     if len(original) > 0 and original.isalpha():
        print original
    else:
        print "empty"

With print original before your conditions, you are printing the input no matter what. Which will not let you pass as you only need to print the input when the input consists of only letters.


#3

Code looks right, except we would not print original before the validation check.


#4

Thanks,
Yes, deleting the first "print original" fixed it. But I have to say it's very frustrating. How am I supposed to know that? I'm a complete novice btw.


#5

Just starting out you have to take some things on faith until you get more acquainted with the language and code constructs. Admittedly, the instructions may be confusing, but avoid letting yourself get frustrated. That only shuts down our imagination and our desire to learn. Dig in for the long haul.


#6

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