5. Computer doesn't know what .isalpha is


#1


When I compile it, it works just fine... until after I put in a word. Then it says this:

Welcome to the Pig Latin Translator!
Enter a word: hello
Enter a Word:
Traceback (most recent call last):
File "python", line 9, in
NameError: name 'isaplpha' is not defined

In my code, I already gave isalpha a value. I had to remove the period or it would give me a syntax error:

File "python", line 4
    .isalpha = "Number Checker"
    ^
SyntaxError: invalid syntax



print 'Welcome to the Pig Latin Translator!'
raw_input("Enter a word:")
original = "Enter a Word:"
isalpha = "Number Checker"
if len(original) > 0 and len(original) < 100:
    print original
else: print "empty" 
isalpha = "Number screening thing" #Pretty self-explanitory here.
if isaplpha(1,2,3,4,5,6,7,8,9,0):
    print "Use proper words."
else:
    print "Great job!"


Please help.


#2
  1. isaplpha(1,2,3,4,5,6,7,8,9,0): is misspelled; you used an extra "p"

  2. str.isalpha() is already a built-in function, but you have defined isalpha as a variable. If you want to test those numbers to see if they are in the alphabet, you would have to do something like this:

if "1,2,3,4,5,6,7,8,9,0".isalpha():

Also, you should switch the last 2 print statements or use the "not" keyword; the last if/else statement will tell you that the string is not numeric when it is, and vice-versa.


#4

Mine worked, example is given below:
I tried with the word J123

print 'Welcome to the Pig Latin Translator!'

Start coding here!

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


#5

And that printed "empty" because x.isalpha() is False.


#6

print 'Welcome to the Pig Latin Translator!'

Start coding here!

original = raw_input("Enter a word:")
if len(original) > 0 or x.isalpha():
print original
else:
print "empty"

Note: Are we supposed to use or statement instead of and. Only then the name prints out?


#7

print 'Welcome to the Pig Latin Translator!'

Start coding here!

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

Note: that also worked.


#8

You should use method .isalpha() for original, not for x.
if len(original)>0 and original.isalpha()


#9

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