How do I use a while loop instead of an if clause, so I can gain familiarity with how to do a while loop?


#1

Continuing the discussion from How to loop Pig Latin Translator, when incorrect input entered?:
UPDATE: this answer is not meant to be repetitive, like I said I already correctly solved the problem
Are you saying I could do something like this:

print 'Welcome to the Pig Latin Translator!'

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

but how would I do that using a while loop?

by the way, this is the correct answer


#2

Hi @jacquesk,

Since you have made this assignment …

empty = "empty"

… the condition on the next line will always evaluate to True, regardless of what the user has entered, because len(empty) will always evaluate to 5.

You really need to be checking original instead of empty.

Try revising your code to fit a pattern similar to the one in this post by @stetim94.


#3

Would you suggest just using “” instead? Instead of empty = “empty”

I see what you’re saying, I should try out different words


#4

Is the above statement correct…now that I have fixed it?


#5

This …

if len(empty) > 0:

… should be …

if len(original) > 0:

#6

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