《Python编程》第七章部分课后练习题

#7-4 披萨配料:

代码:

#7-4 披萨配料
"""
mushrooms
pepperoni
extra cheese
"""

while True:
	message = 'Which Pizza ingredient would you add?'
	message += "\n(Enter 'quit' to end): "
	ingredient = input(message)
	if ingredient == 'quit':
		break;
	else:
		message = '\nWe will add ' + ingredient + ' in the Pizza. \n'
		print(message)

输出:pass


#7-5 电影票:

代码:

#7-5 电影票

while True:
	message = 'Dear gentleman or lady, How old are you?'
	message += "\n(Enter 'q' to end): "
	year = input(message)
	if year == 'q':
		break;
	else:
		year = int(year)
		if year < 3:
			message = 'You are free admission!'
		elif year <=12:
			message = 'You have to pay 10 dollars for the ticket!'
		elif year > 12:
			message = 'You have to pay 15 dollars for the ticket!'
		print(message+'\n')

输出:pass


#7-7 无限循环:

代码:

#7-7 无限循环
#可以尝试,没什么大碍的

while True:
	num = list(range(1, 10**4))

输出:pass


#7-8 熟食店:

代码:

#7-8 熟食店

sandwich_orders = ['Reuben sandwich', 'Club sandwich', 'Doner sandwich']
sandwich_orders.append('Hamburger')
finished_sandwiches = list()
while sandwich_orders:
	sandwich = sandwich_orders.pop()
	message = 'I made your ' + sandwich + '.'
	finished_sandwiches.append(sandwich)
	print(message)

while finished_sandwiches:
	print(finished_sandwiches.pop())

输出:

I made your Hamburger.
I made your Doner sandwich.
I made your Club sandwich.
I made your Reuben sandwich.
Reuben sandwich
Club sandwich
Doner sandwich
Hamburger



#7-9 五香烟熏牛肉(pastrami)卖完了 :

代码:

#7-9 五香烟熏牛肉(pastrami)卖完了 

sandwich_orders = ['Reuben sandwich', 'Club sandwich', 'Doner sandwich']
sandwich_orders.append('Hamburger')
for a in range(0,3):
	sandwich_orders.append('pastrami')

message = 'Sorry. We are out of pastrami.\n'
print(message)

while 'pastrami' in sandwich_orders:
	sandwich_orders.remove('pastrami')

while sandwich_orders:
	print(sandwich_orders.pop())

输出:

Sorry. We are out of pastrami.

Hamburger
Doner sandwich
Club sandwich
Reuben sandwich
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值