Clarification pyglatin

So I’m slowly working through Python 2, I’ve come to the PygLatin component of Conditionals and Control flow. I’ve somehow passed the exercise but I’m confused and not fully comfortable.

When I run the code, my bash will ask me to enter a word twice. I wasn’t sure why it should be asking me twice. I have raw_input("Enter a word: ") in my coding twice, and was wondering if the second instance is triggering the bash to ask a second time? If so, how can I prevent this? I’m using raw_input("Enter a word: ") the second time to tie it to the variable ‘original’.

Can anyone shed any light? Code below.

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"

@adamragg,

Your line of thinking is correct. raw_input gets called twice: once by itself, and once when you’re trying to assign the value of the raw_input to your original variable.

The important thing to recognize here is the difference between the two.

This line by itself…

raw_input("Enter a word: ")

…only prompts the user to input something into the terminal. However, nothing happens with that input and it is not saved.

On the other hand, this line…

original = raw_input("Enter a word: ")

…prompts the user to input something into the terminal and saves that input as the variable original.

Because the first one does nothing, deleting it will solve your repetition problem and will not affect the rest of your code.

Hope this helps clarify things. Happy coding!

3 Likes

Ah ha!

Awesome! Thank you, that clarifies and makes so much sense. I appreciate the feedback and help!