Week 3, Friday: boolean FLAG, vim tips



branching

Write a "bouncer" program that uses a list to decide if people get in to a party or not.

$ python bouncer.py 
What's your name? jeff
You're on the list...welcome to the party.

$ python bouncer.py 
What's your name? valerie
Sorry, you're not on the list.

For this, you could use the in operator, or an accumulator, or what's called a boolean flag. Assume you have two variables: a list of allowed guest names (guestlist), and the name of a possible guest (name):

 # assume they are not on the list
 FOUNDNAME = False

 # now check for name in guestlist, one at a time
 for guest in guestlist:
   if name == guest:
     FOUNDNAME = True

 # at this point, the boolean flag tells if they are on the list or not
 if FOUNDNAME:
   print("You're in...")
 else:
   print("Sorry...")

vim tips and tricks

All of these are from command mode, not insert mode. Hit Esc to get to command mode before trying any of these: