List and Loop Exercises¶

Say Hi to a List¶

Create a list of names and print a personal hello to each person on the list.

Guest List¶

Make a program event.py that asks the user for their name, checks a list of names and either tells them “Welcome THEIR_NAME!” or “Sorry, but you’re not on the guest list”.

Meditative Breathing Guide¶

Open breathe.py and change it to make a program that helps users breathe 6.5 breaths per minute. It should print out “Breath in”, waiting some time, then saying “Breath out”, then repeat. It should do this for 2 minutes (13 total breaths, each with an in and an out).

Lazy Chef Sandwich Generator¶

You’ve just opened a restaurant but you’re too lazy to come up with a sandwich menu. Make a program to do it instead!

Create a program lazy_chef.py that does the following:

  1. Create a list of options for each element of the sandwich (proteins, spreads, bread, etc.).
  2. Print one random item from each of the sandwich elements lists when the program is run.

Example usage:

$ python3 lazy_chef.py
olives
mustard
beef
white bread

Virtual Friend¶

Create a program my_friend.py that does the following:

  1. Asks how you are
  2. Compares the input to a list of good emotions, and a list of bad emotions, then prints an appropriate response depending on which list contains the input
  3. Prints “I truly don’t know what that is like.” if the input isn’t in either list
  4. Chooses a random response if the input “How are you” is received (with any capitalization)

Example usage:

$ python3 my_friend.py
How are you? Good
Oh, that's great!

$ python3 my_friend.py
How are you? Horrible
I'm sorry to hear that

$ python3 my_Friend.py
How are you? Pickles
I truly don't know what that is like.

$ python3 my_friend.py
How are you? How are you?
I like beans.

Better Lazy Chef¶

Expand your lazy chef program to do the following:

  1. Choose a name at random from a name of sandwiches and assign your random sandwich ingredients to that name. Your menu should not include two sandwiches with the same name.
  2. Print out your menu items in a nice, human-readable way.

Hint

If you didn’t make a lazy chef program previously, you can use these lists to start with:

proteins = ["ham", "turkey", "beef", "tofu"]
condiments = ["mustard", "mayo", "hummus"]
veggies = ["tomato", "lettuce", "onion", "sprouts"]
breads = ["white bread", "wheat bread", "pita bread", "sourdough"]

Example usage:

$ python3 lazy_chef.py
The Terminator has turkey, lettuce, and mayo on rye bread.
The First Lady has tofu, tomato, and hummus on pita bread.
The San Diegan has tuna, sprouts, and dill spread on sourdough.

Chore Chooser¶

Make a program chore_chooser.py that does the following:

  1. Create two lists do_now and do_later, along with a list of chores
  2. Assign each item in the list of chores to do_now or do_later at random
  3. Print each list in a nice, human-readable way
$ python3 chore_chooser.py
Do now:
- mop floor
- take out rubbish

Do later:
- dust
- water plants