Clarification Python (Check Yourself)


#1



https://www.codecademy.com/courses/python-beginner-2W5v7/0/4?curriculum_id=4f89dab3d788890003000096


So my code passes and it says proceed to the next lesson, but what I don't understand is why it asks me to "Enter a word:" twice in the output. Even if I enter two different words, the code runs, and it asks me to proceed to the next lesson.

My output
Welcome to the Pig Latin Translator!
Enter a word: dragon
Enter a word: drag
drag
None


I was expecting it to ask me to enter the word only once, and after I hit enter, it would print the word I have entered, and if I leave it blank, for it to print "empty" instead of me having to hit enter twice to get the "empty" message.


print 'Welcome to the Pig Latin Translator!'

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


#2

That line may be removed. It is not a complete statement and does nothing.


#3

Yes, it works properly then. Thank you! I was wondering because it was a part of the code provided when the lesson started.:smiley:


#4

I've been wondering why we see this error so often. Going forward, just be sure that each line is a complete statement. If it is just an expression,

raw_input('...')

a == 42

b + 6

and so on, it is not a statement and parsed or not, nothing is preserved or acted upon.


#5

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