LEN() what is it


#1



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


Welcome to the Pig Latin Translator!
Enter a word: Doug
Traceback (most recent call last):
File "python", line 5, in
TypeError: object of type 'builtin_function_or_method' has no len()


When I'm running this code it lets me enter a name but then throws the error above. I'm confused because I don't know what len(original) is and how I'm supposed to use it in this exercise. Did I miss a lesson where they explained what len() is and how to use it?


print 'Welcome to the Pig Latin Translator!'

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


#2

you only need to prompt the user once, why do you have raw_input's?

the second function is missing parentheses, causing it to be a built_in_function, which doesn't have length


#3

In this statement you are assigning the raw_input function to the variable original. A function does not have a len method. Remove this line, and edit the line above to assign to original.


#4

Hey thanks for the reply!

I left original = raw_input in place because it was part of the default code on the right so I assumed I needed to use it. Since I think this lesson is before the lesson on functions, it's got me a bit confused because I don't know how functions really work yet :sweat:


#6

Is this what you mean?

print 'Welcome to the Pig Latin Translator!'
name = original("Enter a word:")
if len(original) > 0: 
        print original
else:
        print "empty"

which results in

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

#7

Hey thanks for the help, I figured it out! I put my variable 'name' in to the len() function and then it made sense to me.


#8

The instructions ask for original as the input variable.

original = raw_input("Enter a word:")

#9

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