第七章

7-1

car = input('Please tell me which kind of car you want:\n')
print('Let me see if I can find you a ' + car + ' .')

7-2

seats = int(input('How many seats do you want?\n'))
if seats > 8:
	print('Sorry, but there are not enough seats.')
else:
	print('Please come in, there are enough seats.') 

7-3

num = int(input('Please enter an integer:\n'))
if num % 10 == 0:
	print(str(num) + ' is a multiple of 10.')
else:
	print(str(num) + ' is not a multiple of 10.')

7-4

prompt = 'Please tell me the ingredients of pizza that you like:\n'
prompt += "Enter 'quit' to end the program.\n"
while True:
	message = input(prompt)
	if message == 'quit':
		break
	else:
		print('We will add this ingredient into pizzas.')

7-5

prompt = 'Please tell me your age, and I will show you the price:\n'
prompt += "Enter 'quit' to end the program.\n"
while True:
	age = input(prompt)
	if age == 'quit':
		break
	else:
		age = int(age)
		if age < 3:
			print('Your ticket is free.')
		elif age >= 3 and age <= 12:
			print('Your ticket is 10 dollars.')
		else:
			print('Your ticket is 15 dollars.')

7-7

while True:
	print('This will not stop.')

7-8

sandwich_orders = ['pork sandwich','beef sandwich','chicken sandwich']
finished_sandwich = []
while sandwich_orders:
	sand = sandwich_orders.pop()
	print('I made your ' + sand + ' .')
	finished_sandwich.append(sand)
print('All the sandwiches are finished:')
for sand in finished_sandwich:
	print(sand)

7-10

survey = {}
while True:
	name = input('What\'s your name?\n')
	prompt = 'If you could travel around the world, '
	prompt += 'where would you go?\n'
	place = input(prompt)
	survey[name] = place
	re = input('Would you like to let others answer this question?(y/n)\n')
	if re == 'n':
		break
for name,place in survey.items():
	print(name + " wants to travel to " + place + ' .') 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值