(5. Check Yourself....Some More) My code is half correct, and half wrong. Feedback needed


#1



My code passes the simulation if I leave the input empty, have numbers and letter, or have only numbers. I do not pass the simulation if I enter only letters, instead I receive an error message. For accuracy sake I'd like it to run correctly each time.


Error Message: Oops, try again. It looks like your code does not print original ("kat") when original is only made up of alphabetical characters.


Code: 
print 'Welcome to the Pig Latin Translator!'

original = raw_input("Enter a word")# Start coding here!
if len(original) > 0 and original.isalpha():
    print "orignal"
else:
    print "empty"


#2

It's just print original. Not print "original". You want to print what you entered. Right now, you're printing "original" everytime.


#3

Thanks. That seems to have worked.

For clarification since I'm a beginner I'm assuming that original doesn't need " " because it is already defined, where as empty needs " "s because it is not?


#4

No. "" is for strings...kind of like texts. In this exercise, they wanted you to print what you've inputted. You've used the variable original to store it.

It doesn't necessarily mean that anything with "" is not defined.
For example, you can do this(elsewhere, not in lesson) and no error will come up:

original = raw_input("Enter any word: ")
print original #prints what the user types eg. if user typed "cat", it will print "cat"

print "original" #prints "original"

As you can see, original is defined but you can still print "original".
One is a variable and the other is a string. That's all.


#5

Thank you! That clears a lot up. I appreciate the detailed response.


#6

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