python课程作业——第7章 字典

第7章 字典

这里写图片描述

# 7-8
sandwich_orders = ['tuna sandwich', 'peanut sandwich', 'veal sandwich']
finished_sandwiches = []
while sandwich_orders:
    sandwich = sandwich_orders.pop()
    print('I made your ' + sandwich)
    finished_sandwiches.append(sandwich)

# 7-9
sandwich_orders = [
    'tuna sandwich', 'peanut sandwich', 'pastrami', 'veal sandwich',
    'pastrami', 'pastrami'
]
print('Pastrami has sold out')
while 'pastrami' in sandwich_orders:
    sandwich_orders.remove('pastrami')
print(sandwich_orders)

# 7-10
responses = {}

polling_active = True
while polling_active:
    name = input("\nWhat is your name? ")
    response = input(
        "If you could visit one place in the world, where would you go? ")
    responses[name] = response
    repeat = input("Would you like to let another person respond? (yes/ no) ")
    if repeat == 'no':
        polling_active = False
print("\n--- Poll Results ---")
for name, response in responses.items():
    print(name + " would like to visit " + response + ".")

猜你喜欢

转载自blog.csdn.net/yeziqing10/article/details/80628778