Check yourself


#1


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

error message:

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

have no idea why it shouldn't work. whatever I tried I keep on getting this error message


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"


#2
variable = function()

not

function()
variable = function

#3

wow how could I have not seen that. thanks!


#4

do you know however why the error message kept on referring to line 7?


#5

It traces back to the previous line. raw_input is a built-in function, but we wouldn't normally write it without () unless we are passing a function back from another function, to be invoked later.

original = raw_input

Now original is a copy of the function. We can invoke it to perform the same function...

word = original("Enter a word")

Eg.

>>> original = raw_input
>>> word = original("Enter a word: ")
Enter a word: transference
>>> word
'transference'
>>>

#6

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