Understanding while loops


#1

Hi,
I am trying to write a simple code that requires the user to input his name but if the input is blank, it takes him back to the first input again until he enters a letter or number:

print "Hello! Welcome to the Trivia "
begin = raw_input ("Would you like to begin?: ")
while True:
  begin == ""
  print "You have to write something..."
  break
if begin.lower() == "yes" or begin.lower() =="y":
  print "Good choice, You got to risk it to earn the  biscuit"

How do I do this so the loop works as kind of an “if” as well. If the user inputs a blank it would take him back to the beginning but if not, it will allow him to continue.
Thanks


#2

you can’t take him back to the first input, to achieve this you would need:

while True:
   # get input
   # check if input is valid:
       # input is valid, print a message and break the loop

#3

I dont understand what I am doing wrong.

print "Hello! Welcome to the Trivia "
begin = raw_input ("Would you like to begin?: ")
while not True:
if begin.lower() == “yes” or begin.lower() ==“y”:
break
print “Thanks for typing an answer”
begin == “”
print “You have to write something…”
name = raw_input ("Please insert your name: ")
and continues…

I want the code to validate there has been an input and if so, proceed to the next question. If not, take him back to the name input requirement until he writes something valid in. I didnt understand your previous answer
thanks


#4

you would need to create separate loops for the different questions, given the loop is how you keep prompting for input until you have something valid (then you break the loop)