Input being read incorrectly (when it seems correct)?


#1

***A screenshot is shown below
In this lesson, I'm asked to enter a word to be converted into PygLatin-form. To check if the word is a valid input, I'm asked to use an if-statement to test for two things: If the entered input is greater than 0 and if the input contains only letters. If either of these tests returns false, my else-statement prints "empty".

However, when I run my code and enter my name, "Brandon", my program returns "empty" and it doesn't seem to make sense. Is there something I might be doing wrong? Thoughts and advice are most welcome!


#2

@bitwhiz30130 pls refresh your page maybe , error go away. coz i don't see any mistake in your code.


#3

Looks like you wrote " Brandon" (with a leading space)
But why guess? print it out:

print repr(original)

(repr retains the quotes, useful for telling where the string starts and ends)


#4

I tried refreshing and I'm getting the error. I figured that the code was correct as well.


#5

When I tried out your suggesting, I came up with this:

What does that "u" mean?


#6

I noticed that when I type "Brah", this happens:

This output makes sense because it satisfies both the if-statement's conditions. It's length is greater than zero and it's only letters.


#7

This should not be happen, as there's no limit on word we use,

print 'Welcome to the Pig Latin Translator!'

Start coding here!

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

use this see if there's any prblm


#8

i tried searching the reason for that 'u' in the output...i got nothing ..!!
did you find anything ?
cause i tried using that 'repr' method ...its giving me same answer as yours ..!!!


#9

the u means it's a unicode string, you don't need to do anything about it. Just consider it a string, because that is what it is)

There's also a space at the end of your string.

I thought it would be at the start of the string though, since in your console window there is a space after "Enter a word:" but there isn't a space there from what I can tell in your call to raw_input, and raw_input doesn't add that space on its own.


#10

akurlvv, that is exactly what I've been coding this whole time. I think there's something wrong with the course that's beyond my control as a user. I think they've fixed it and I've now been able to get the result I expected in the first place:


#11

WAIT NEVERMIND... it still returns "empty" on the next lesson:


#12

The program returns "Welcome to the Pig Latin Translator!" like it should (it doesn't when you add the condition that the input has to be only letters). It's the input "Brandon" that seems to be the problem input whenever I add that isalpha() condition.