Whats wrong with my code? im so confused


#1


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

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


print 'Welcome to the Pig Latin Translator!'


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


#2

That's not how they wanted you to define original. What Codecademy wants you to do is take the raw_input of the user:

raw_input("Enter a word: ")

And store it under the variable original:

original = raw_input("Enter a word: ")

Do you understand your mistake now?


#3

This is my code below, and all that happens is that once I enter a word, the computer just keeps spinning. I have tried modifying it and I don't know what I am doing wrong. Please, please help! I want to continue with my lessons.

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"


#4

raw_input() is a function, not a variable. When you have original = raw_input() that raw_input is not referring to the previous time you used it and asked for a word, it is now asking for new input, but because there is nothing in the parentheses, it does not display anything on the screen telling you what is happening.

If you use original = raw_input("Enter a word: ") you'll be good.


#5

That doesn't work, because when I do that this is what I get as output. Notice how instead of printing Five it literally repeats "enter a word".

Welcome to the Pig Latin Translator!
Enter a word: Five
Enter a word:

Here is the code with your suggested modification:

print 'Welcome to the Pig Latin Translator!'

Start coding here!

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


#6

You have raw_input("Enter a word:") twice, so you are asking the user to enter a word twice. The first one is not actually assigning the value received to anything, so it asks for an input and doesn't do anything with it. The second one asks for an input and assigns that input to "original".

Remove the first raw_input() so you are left with:

print 'Welcome to the Pig Latin Translator!'

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

#7

That was indeed the problem!!! Thank you soooooo much!


#8

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