Numbers not detecting even i add .isalpha()


#1



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


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

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


print 'Welcome to the Pig Latin Translator!'

original = raw_input("Enter a word:")
print original
if len(original) > 0 and original.isalpha():
    print original
        #Run this block.
        #Maybe print something?
else:
     print original


AND LAST LINE IS else:
                                   print original or print empty?


#2

numbers aren't alphanumeric characters? isalpha only works for a-z and A-Z.

if you also want to validate numbers use regex

regex is a bit tricky


#3

but it should give a false statement when i enter a number rite/. but it doesnt show output at all

suppose if i type python123 what output should i receive?


#4

the problem is in your else clause (sorry, i should have seen it the first time), when you enter something invalid (python123 for example) it should not print original, instead try something like:

print "you can only use letters"

this can be anything, just don't print original, that should only happen when the user input is valid


#5

ya now when i use python123 it says the following in console.. (below)

Welcome to the Pig Latin Translator!
Enter a word: python 123
python 123
you can use only letters
None

but it also shows a error message(below)
Oops, try again. It looks like your code prints original ("python 123") when original includes non-alphabetical characters.


#6

can you post an updated version of your code?


#7

try removing the "print original" on line 4 as it will execute it b4 processing the if else statement.


#8

to the Pig Latin Translator!'

original = raw_input("Enter a word:")
print original
if len(original) > 0 and original.isalpha():
print original
#Run this block.
#Maybe print something?
else:
print "you can use only letters"


#9

@caveman928

thank you .. once i remove it it displays o/p without error