4. Check Yourself


Hi, I'm stuck at "PygLatin 4. Check Yourself"

My code:

print 'Welcome to the Pig Latin Translator!'

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

if len(original) != "0":
print original

elif len(original) == "0":
print "empty"

When I enter a word, it gives me

"Traceback (most recent call last):
File "python", line 6, in
TypeError: object of type 'builtin_function_or_method' has no len()"

When I hit enter without a word, it won't print empty either.

What am I doing wrong, and can you explain how the correct way works


original = raw_input

You assign a function to original, and then you try to get the length of original, something that it does not have, because it's a function.


original = raw_input was already given.


basically, the raw_input is a function that as been given by the python code, theerfore it has no len. the raw_input is a built in function and has no len. to fix this, you assign the original variable to raw_input("Enter a word;") sort of like this

original = raw_input("Enter a word:")

so you have to assign the raw input into the variable. you can get rid of the second line of code and just put one line @asmathecoder


Thank you so much man! I honesty did not catch that.
My only other problem is that it says I need to use both if and else.

I used elif and whenever I change it to else it gives me this

File "python", line 8
else len(original) == "0":
SyntaxError: invalid syntax

Here's my changed code

print 'Welcome to the Pig Latin Translator!'

original = raw_input("Enter a word:")

if len(original) != "0":
print original

elif len(original) == "0":
print "empty"


you don't put any conditions after else. It's just else.

    print "empty"


Thanks! Now it works when I enter a word, but when I hit enter without typing in a word, it still doesn't print "empty" (it allows me to continue to the next lesson though)


Remove the quotation marks around your 0's.


Thanks it works 100% now.


You don't need to use elif in this code, since there is only this and that
not or. Instead of using elif, try using else. That should work better.
Also, make sure to Indent properly!


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