Output is bizzare


#1

Case 1.
Error Message- It looks like your code does not print original ("cloudy") when original is only made up of alphabetical characters.
This error comes up when I do not give the word cloudy under quotes.

Output:
Welcome to the Pig Latin Translator!
enter a word: cloudy
The word is cloudy
None

Since my input was not given under quotes, I expected something else.

Case 2: When I would give cloudy word under quotes, it should be perfectly fine but instead it returns empty.

Output
Welcome to the Pig Latin Translator!
enter a word: "cloudy"
empty
None

Case 3: For empty string, it works fine.

Output
Welcome to the Pig Latin Translator!
enter a word:
empty
None

print 'Welcome to the Pig Latin Translator!'

original=raw_input("enter a word:")
if len(original) > 0 and original.isalpha():
    print "The word is " + original
else:
    print "empty"

#2

What happens if write "cloudy" in quotes?

""cloudy""

Now we have two strings sandwiching an undefined variable, which is ignored it would seem. The return value will be empty.


#3

The "cloudy" is just one string. I do not understand why it would be two and an undefined variable. Please explain


#4

raw_input returns string data. If we quote the input then it gets quoted a second time, hence, ""cloudy"".

Try with escapes and see what happens (report the result)

\"cloudy\"

However, I am just speculating, so cannot explain as it were. Only guess.

In Python 3 raw_input is gone, and input now returns a string:

>>> input("...")
..."cloudy"
'"cloudy"'
>>> input("...")
...'cloudy'
"'cloudy'"
>>>

My theory is melting away.


#5

I tried with the word \"cloudy\"
Output:
Enter a word: \"cloudy\"
empty
None
Error -Oops, try again. It looks like word is set to "cloudy" instead of "\"cloudy\"".

Same is the case with "cloudy"
Output: Enter a word: "cloudy"
empty
None
Error: Oops, try again. It looks like word is set to "cloudy" instead of ""cloudy"".


#6

I think it's safe to say we should not quote values we input, at least not for this exercise.


#7

Oh ok Thanks for the help. :slight_smile:


#8

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