Traceback error


#1

Ok, so everything seems to work fine until I type the word into the console.
print 'Welcome to the Pig Latin Translator!'

Start coding here!

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

Once I do type it in and press enter THIS godforsaken message comes up. I have tried everything I can think of to fix this, but it just wont work.

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


#2

If you write it this way, the entered word won't be stored anywhere, because you only call the function, and want the user to type something. :slightly_smiling:

Here you try to assign the function 'raw_input' to the variable 'original', but not the typed word from above :confused:

Try to write this instead:

original = raw_input("Enter a word:")

this way, you assign the entered word, to the variable 'original'. If you start the programme it will print:
Enter a word: <- You can type here, and it will be stored in original :smiley:


#3

You should check your whitespace and indenting to see if that helps. For the translator part of the exercises I ended up with this:

pyg = 'ay'

original = raw_input('Enter a word:')
word = original.lower()
first = word[0]
new_word = word + first + pyg
new_word = new_word[1:]
if len(original) > 0 and original.isalpha():
print new_word[1:]
else:
print 'empty'

Maybe this will help. I can see that you need to indent your if and else lines and the len function should not have a space in between len and the (. It should be len(original). Python is really the only programming language that I haven't worked with. I just started yesterday but I can see that Python relies on the right amount of spacing and indenting a lot because it doesn't use semicolons, etc. to end statements.


#4

I just noticed that when you copy/paste your code into this forum that it takes all of the indenting away. But basically my two print functions are indented and that's it. Ignore what I said about indenting the if and else lines. I don't know why I put that. But the spacing matters a lot. i.e. in the len(original)


#5

Thank you so much Frozen, I never thought to do it that way!

Also, how did you put the code in like that? indents and what not.


#6

You're welcome :slightly_smiling:

Just paste your code into the the text area and mark all of it. Then click on </> and your code will be like that.
And for the quote, mark the part you want to quote with your mouse, and it will say ""quote reply, click it, and it will paste it into the text area