In the example in the instructions, an empty string is assigned to the empty_string variable, and then the length of that is checked, using the len() method.
In our code, we want to check the user’s input, which we stored in a variable called original, so we’d just have to use len() on that and compare against 0.
If you think you’ve done it correctly but aren’t able to pass, be sure you’ve put a colon : after your if and else, and that you’ve properly indented the code inside of each. The editor should automatically indent your code after you type a colon and press enter, letting you know you’ve done it correctly. Check the indentation of the example in the instructions if you need a reminder of how to do this!
I am getting the same “TypeError: object of type ‘builtin_function_or_method’ has no len()” regardless of whether my string has zero or any number of characters in it.
To answer, we must see the code indented as you wrote it. Please use the code icon </> that is near the middle of the menu bar at the top of the text box you are typing in.
Hi, Adam did you solve your question? I hope you did, but for what I can tell the error is that the input the user is typing is not stored in original and you are telling the program to test the length of the original.
Can someone explain to me why saving raw_input() on original as line 5 doesn’t work
print 'Welcome to the Pig Latin Translator!'
# Start coding here!
raw_input('tell me a word')
original=raw_input()
if len(original)>0:
print original
else :
print 'empty'
raw_input() that meaning type some thing in the screen and everything in double round brackets after raw_input will show on screen as a comment
in line 4 : raw_input(‘tell me a word’) It will show on the screen: tell me a word, then you type something BUT IT NOT SAVE
IN LINE 5 original=raw_input() It will show on the screen: because double round brackets after raw_input is a blank and original=raw_input() is waiting the value you type on screen show it doesn’t work
I have the same code and it does not work. any ideas?
print ‘Welcome to the Pig Latin Translator!’
Start coding here!
original = raw_input(‘Enter a word:’)
#check if user typed something
if len(original) > 0 and original.isalpha():
print original
else:
print ‘empty’
I get:
Welcome to the Pig Latin Translator!
Enter a word:
Traceback (most recent call last):
File “python”, line 4, in
ExecTimeoutException: Program took too long to terminate.
If refreshing and other trick doesn’t work, then the fallback is to create a string literal and use that to run the program without getting the solution.