Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

TypeError: object of type 'builtin_function_or_method' has no len() Codeacademy [closed]

Tags:

python

Hi I'm a beginner working with code academy. I've asked this question in several venues and searched everywhere, can't figure out the problem.

The goal is to verify that users have answered the question. Here is my code

print 'Welcome to the Pig Latin Translator!'

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

When I execute the code and enter a word, it gives me this error:

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

I've tried many variations of the code, I don't understand what is happening. I really appreciate any and all input.

like image 573
DataScienceAmateur Avatar asked Sep 05 '25 19:09

DataScienceAmateur


1 Answers

You are trying to get the length of the raw_input function. The actual result of the function call on the previous line you ignored.

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

You want to store the output of the function call in original instead:

original = raw_input("Enter a word: ")
if len(original) > 0:
    print original
else: 
    print "empty"
like image 183
Martijn Pieters Avatar answered Sep 08 '25 08:09

Martijn Pieters