Pig Latin len() error


#1

https://www.codecademy.com/courses/learn-python/lessons/pyglatin/exercises/check-yourself?action=lesson_resume

If i run the code it gives out:
TypeError: object of type ‘builtin_function_or_method’ has no len()

I thougth len() is a built in command/function that doesn’t need an import or anything, yet it fails in this case. I tried to refresh, retype, copy paste from the instructions… neither works.

```python
print 'Welcome to the Pig Latin Translator!'

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

if len(original) > 0:
  print (original)
else:
  print ("empty")
<do not remove the three backticks above>

#2

Hi @satinivy,

The problem here has nothing to do with your use of len(). The error you are receiving is because of these two lines:

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

Allow me to explain; This:

raw_input("Enter a word: ")

is great and all, but it isn’t being stored anywhere. Meanwhile, this:

original = raw_input

What you have done here is set original equal to the built-in function itself. That’s not what we want.


#3

lets see what original is:

print 'Welcome to the Pig Latin Translator!'

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

oops, that is not right. What happened? You call raw_input twice, but the second time, you don’t include the parenthesises, so now it store the function itself in original variable

you only need to ask the user for input once, so you need 1 raw_input


#4

I see, thank you you two :slight_smile:
Makes perfect sense now, I just got rly confused by the error message and understood it incorrectly!


#5

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