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:
- Create a list of options for each element of the sandwich (proteins, spreads, bread, etc.).
- 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:
- Asks how you are
- 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
- Prints âI truly donât know what that is like.â if the input isnât in either list
- 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:
- 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.
- 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:
- Create two lists
do_now
anddo_later
, along with a list of chores - Assign each item in the list of chores to
do_now
ordo_later
at random - 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