Class 20 – October 9

You are so controlling

While I can go on – I do not repeat myself – Always a new way


Look both ways


Agenda


Problems


Whiling away

while ( test expression ) :

  action

looking_for_a_yes_or_no = True

while ( looking_for_a_yes_or_no ) :

  reply = input( 'Enter (yes / no): ' )

  reply = reply.lower()

  if ( reply in [ 'yes', 'no' ]

  looking_for_a_yes_or_no = False

while ( test expression ) :

  action

else :

  action

looking_for_a_yes_or_no = True

while ( looking_for_a_yes_or_no ) :

  reply = input( 'Enter (yes / no): ' )

  reply = reply.lower()

  if ( reply in [ 'yes', 'no' ]

  looking_for_a_yes_or_no = False

else :

  print( 'your reply of', reply, 'is accepted' )

Note, I have never needed to use else for a while statement in practice.



To do