Python编程从入门到实践 课后习题7-8、7-9、7-10

7-8

sandwich_orders =['chicken','beef','fish','egg','cheese']
finished_sandwiches = []
while sandwich_orders:
    sandwich = sandwich_orders.pop()
    print("I made your " + sandwich + " sandwich.")
    
    finished_sandwiches.append(sandwich)
    
for finished_sandwich in finished_sandwiches:
    print(finished_sandwich.title())

7-9

sandwich_orders =['chicken','pastrami','beef','pastrami','fish','egg','pastrami','cheese']
finished_sandwiches = []
print("五香烟熏牛肉卖完了")
while 'pastrami' in sandwich_orders:
    sandwich_orders.remove('pastrami')
    
while sandwich_orders:
    sandwich = sandwich_orders.pop()

    finished_sandwiches.append(sandwich)
    
for finished_sandwich in finished_sandwiches:
    print(finished_sandwich.title()) 

7-10

responses = {}
active = True
while active:
    name = input("What's your name?\n")
    question = input("If you could visit one place in the world, where would you go?\n")
    responses[name]= question 
    
    repeat = input( "你想停止问卷吗?(yes/no)\n")
    if repeat == 'yes':
        active = False
print("---调查结果---")
for name,question in responses.items():
    print(name + " 想去的地方是 " + question)
发布了6 篇原创文章 · 获赞 1 · 访问量 80

猜你喜欢

转载自blog.csdn.net/watermelon_lily/article/details/103488639