Check yourself!


#1



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


Traceback (most recent call last):
File "python", line 3, in
AttributeError: 'unicode' object has no attribute 'isalpha'


I expect it to print correctly checking to see if there is numbers or not! Can someone tell me what I am doing incorrectly?

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


#2

Two things, first the error...

Check the spelling of the method name.

We can pass the prompt to the function...

original = raw_input("Enter a word: ")

I suspect that writing this...

caused Python to return unicode, and not string data, hence,

AttributeError: 'unicode' object has no attribute 'isalpha'

By including the prompt in string form in the call to raw_input() we must be turning on the String switch. Not sure, but the behavior suggests it. More reading needed (Python 2.7.x).


#3

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