Last active
November 30, 2022 11:49
-
-
Save jmangrad/f8c3c5383ec8b4c3c1fa1aed04e0f068 to your computer and use it in GitHub Desktop.
Python Crash Course
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
7-8. Deli: Make a list called sandwich_orders and fill it with the names of various | |
sandwiches. Then make an empty list called finished_sandwiches. Loop | |
through the list of sandwich orders and print a message for each order, such | |
as I made your tuna sandwich. As each sandwich is made, move it to the list | |
of finished sandwiches. After all the sandwiches have been made, print a | |
message listing each sandwich that was made. | |
7-9. No Pastrami: Using the list sandwich_orders from Exercise 7-8, make sure | |
the sandwich 'pastrami' appears in the list at least three times. Add code | |
near the beginning of your program to print a message saying the deli has | |
run out of pastrami, and then use a while loop to remove all occurrences of | |
'pastrami' from sandwich_orders. Make sure no pastrami sandwiches end up | |
in finished_sandwiches. | |
7-10. Dream Vacation: Write a program that polls users about their dream vacation. | |
Write a prompt similar to If you could visit one place in the world, where | |
would you go? Include a block of code that prints the results of the poll. | |
7.8 Answer | |
sandwich_orders = ['pastrami', "hamburger", "cheese burger", 'pastrami', "chicken sandwich", 'pastrami', "big mac", "whopper burger"] | |
finished_sandwiches =[] | |
while sandwich_orders: | |
current_sandwich = sandwich_orders.pop() | |
print("I made a " + current_sandwich) | |
finished_sandwiches.append(current_sandwich) | |
print() | |
for finished_sandwich in finished_sandwiches: | |
print(finished_sandwich + " is done\n") | |
7.9 Answer | |
sandwich_orders = ['pastrami', "hamburger", "cheese burger", 'pastrami', "chicken sandwich", 'pastrami', "big mac", "whopper burger"] | |
finished_sandwiches =[] | |
print("The Deli has run out of pastrami") | |
while 'pastrami' in sandwich_orders: | |
sandwich_orders.remove('pastrami') | |
print() | |
while sandwich_orders: | |
current_sandwich = sandwich_orders.pop() | |
print("I made a " + current_sandwich) | |
finished_sandwiches.append(current_sandwich) | |
print() | |
for finished_sandwich in finished_sandwiches: | |
print(finished_sandwich.title() + " is done") | |
7.10 Answer | |
poll = {} | |
while True: | |
name = input('What is your name? ') | |
choice = input('If you could visit one place in the world, where would you go? ') | |
another_choice = input("Would you like to ask more people? ") | |
poll[name.title()] = choice.title() | |
if another_choice == 'no': | |
break | |
print("-----Poll Results----") | |
for x, y in poll.items(): | |
print("{}'s favorite destination is {} ".format(x, y)) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment