Problem 4 "Check yourself!" What is wrong with my code


#1



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"


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


Replace this line with your code.


#2

There is your problem, What do the instructions say to do?


#3

Write an if statement that verifies that the string has characters.

Add an if statement that checks that len(original) is greater than zero. Don't forget the : at the end of the if statement!
If the string actually has some characters in it, print the user's word.
Otherwise (i.e. an else: statement), please print "empty".
You'll want to run your code multiple times, testing an empty string and a string with characters. When you're confident your code works, continue to the next exercise.


#4

How is that the problem btw? That's straight from the previous instructions?


#5
original=raw_input

This statement copies the string representation of the function, raw_input. We would never do that unless it was our intention to substitute a different name to the function. Try it...

name = original("What is you name?")

It will behave exactly the same as raw_input() since it is the same function, only by a different name.

We need to assign the return from raw_input() to the variable, original, instead of name and remove the other line.


#6

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