Python 从入门到实践 7-8 课后习题
2017-12-14 21:16
756 查看
7.8
熟食店:创建一个名为sandwich_orders 的列表,在其中包含各种三明治的名
字;再创建一个名为finished_sandwiches 的空列表。遍历列表sandwich_orders,对于
其中的每种三明治,都打印一条消息,如I made your tuna sandwich,并将其移到列表
finished_sandwiches。所有三明治都制作好后,打印一条消息,将这些三明治列出来。
7.9五香烟熏牛肉(pastrami)卖完了:使用为完成练习7-8 而创建的列表
sandwich_orders,并确保'pastrami'在其中至少出现了三次。在程序开头附近添加这样
的代码:打印一条消息,指出熟食店的五香烟熏牛肉卖完了;再使用一个while 循环将
列表sandwich_orders 中的'pastrami'都删除。确认最终的列表finished_sandwiches 中
不包含'pastrami'。
7.10梦想的度假胜地:编写一个程序,调查用户梦想的度假胜地。使用类似于“If
you could visit one place in the world, where would you go?”的提示,并编写一个打印调
查结果的代码块。
问题: 7.10输出时候,最后刚开始用的直接打印,代码为(print("The " + str(place) " + " you want to go. "))
输出为 The ['Sydney'] you want to go.
熟食店:创建一个名为sandwich_orders 的列表,在其中包含各种三明治的名
字;再创建一个名为finished_sandwiches 的空列表。遍历列表sandwich_orders,对于
其中的每种三明治,都打印一条消息,如I made your tuna sandwich,并将其移到列表
finished_sandwiches。所有三明治都制作好后,打印一条消息,将这些三明治列出来。
sandwich_orders = ['Pice','Noy','Pop'] finished_sandwichers=[] while sandwich_orders: finished_sandwicher = sandwich_orders.pop() print("I made your " + str(finished_sandwicher) +" sandwich.") finished_sandwichers.append(finished_sandwicher) print(str(finished_sandwichers)) for finished_sandwicher in finished_sandwichers: print(finished_sandwicher.title())
7.9五香烟熏牛肉(pastrami)卖完了:使用为完成练习7-8 而创建的列表
sandwich_orders,并确保'pastrami'在其中至少出现了三次。在程序开头附近添加这样
的代码:打印一条消息,指出熟食店的五香烟熏牛肉卖完了;再使用一个while 循环将
列表sandwich_orders 中的'pastrami'都删除。确认最终的列表finished_sandwiches 中
不包含'pastrami'。
sandwich_orders = ['tofu','Pice','pastrami','Noy','pastrami','Pop','pastrami'] print("The pastrami has been sold.") while 'pastrami' in sandwich_orders: sandwich_orders.remove('pastrami') print(sandwich_orders)
7.10梦想的度假胜地:编写一个程序,调查用户梦想的度假胜地。使用类似于“If
you could visit one place in the world, where would you go?”的提示,并编写一个打印调
查结果的代码块。
place=[] print("If you could visit one place in the world, where would you go?") #设置标志位 polling_active = True while polling_active: new_place = input("\n Please input the place?") place.append(new_place) repeat = input("Would you want to input another place?(Y/N)") if repeat == 'N': polling_active = False for i in place: print("The " + i + " you want to go.")
问题: 7.10输出时候,最后刚开始用的直接打印,代码为(print("The " + str(place) " + " you want to go. "))
输出为 The ['Sydney'] you want to go.
相关文章推荐
- Python 从入门到实践 5-3 课后习题
- Python 从入门到实践 5-1 课后习题
- Python 从入门到实践 5-8 课后习题
- Python 从入门到实践 8-12 课后习题
- Python 从入门到实践 7-1 课后习题
- Python 从入门到实践 8-9 课后习题
- Python 从入门到实践 7-4 课后习题
- Python 从入门到实践 8-3 课后习题
- Python 从入门到实践 8-1 课后习题
- Python 从入门到实践 8-6 课后习题
- Python 从入门到实践 6-1 课后习题
- Python 从入门到实践 6-7 课后习题
- 《Python编程 从入门到实践》第十章课后习题
- Python编程:从入门到实践(课后习题10)
- 《Python编程 从入门到实践》第二章课后习题
- python从入门到实践 第十章习题(高级编程技术 week5-2)
- 《Python编程-从入门到实践》课后习题(6)
- Python编程:从入门到实践(课后习题5)
- python 从入门到实践 第五章习题 (高级编程技巧 week3-1)
- python 编程 入门到实践 第三章 列表部分 (课后题加原书)