''' Purpose: repeatedly prompt the user until they reply with a yes or no. The case of the letters do not matter. ''' looking_for_a_yes_or_no = True # have_found_a_yes_or_no = False # while ( have_found_a_yes_or_no == False ): is also a totally valid while condition # as long as the ENTIRE expression is True, the while loop continues to run # as long as you keep track of what your condition is and how you change it, # you should be able to get the same output while ( looking_for_a_yes_or_no == True ): print( "looking_for_a_yes_or_no is", looking_for_a_yes_or_no ) reply = input( "Enter (yes / no): " ) reply = reply.lower() # Several valid algorithms! And one not-so-valid algorithm. # if ( ( reply == 'yes' ) or ( reply == 'no' ) ): # # THIS IS NOT AN IF LOOP; THIS IS AN IF STATEMENT IN A WHILE LOOP # looking_for_a_yes_or_no = False # if ( reply == 'yes' ): # looking_for_a_yes_or_no = False # if this line isn't here, the while loop will go on forever # # if you don't set the condition to be False at some point, the while loop will never end # elif ( reply == 'no' ): # looking_for_a_yes_or_no = False # if ( reply == 'yes' ): # looking_for_a_yes_or_no = False # if ( reply == 'no' ): # looking_for_a_yes_or_no = False # Please don't do this. if ( reply in ['yes', 'no'] ): looking_for_a_yes_or_no = False # this sets looking_for_a_yes_or_no equal to False so that the loop STOPS else: pass print( "looking_for_a_yes_or_no is", looking_for_a_yes_or_no ) print( "Your reply of", reply, "is acceptable!" ) # while loop: # like a for loop, a while loop helps us repeat an action # we know how many times we need to iterate with a for loop (or we have an idea of it based on # user input), but the while loop just repeats based on a certain condition # the while loop repeats when the boolean expression in parentheses is True and stops when it's False, # so make sure you are appropriately keeping track of the condition's boolean value # anything you can do with a for loop, you can do with a while loop, and vice versa! # if it helps, have an analogy! # You've lost your shoe in your bedroom. You can tell yourself: "For every object in this room (the bed, # the bookshelf, the closet, etc.), I'll check for my shoe." That's like a for loop. # OR you can tell yourself: "While I haven't found my shoe, I will examine objects in my room." # (or "Until I've found my shoe, I will examine objects in my room.") That's like a while loop.