Python第七章课后作业

7-1汽车租赁:
str=input('What car do you want ')
print('Let me see if I can find you a',str1)

运行结果:


7-2餐厅订位:
str1=input('How many people will come to the dinner:')
str1=int(str1)
if str1>8:
	print('No empty table')
else:
	print('There are empty table')

运行结果:



7-3 10的整数倍:
num=int(input('Please input a number:'))
print('The number is times of 10') if num%10==0 else print('The number is not times of 10')

运行结果:


7-4 比萨配料:
mes=input('Please input favor,"quit" to quit\n')
while mes!='quit':
	print('We will add',mes,'to the pizza')
	mes=input('Please input favor,"quit" to quit\n')

运行结果:


7-5 电影票:
num=input('Please input your age,"quit" to quit\n')
while num!='quit':
	num=int(num)
	if num<3:
		print('Free')
	elif num>=3 and num<12:
		print('10 dollars')
	else:
		print('15 dollars')
	num=input('Please input your age,"quit" to quit\n')

运行结果:


7-6三个出口:
active=True
while active:
	num=input('Please input your age,"quit" to quit\n')
	if num=='quit':
		break
	num=int(num)
	if num<3:
		print('Free')
	elif num>=3 and num<12:
		print('10 dollars')
	else:
		print('15 dollars')

运行结果:

同上一题

7-7无限循环:
active=True
while active:
	print('hhh')

运行结果:


按了ctrl+c并没有反映。。。。。不知道为什么

7-8熟食店:
sandwich_orders=['apple sandwich','banana sandwich','orange sandwich']
finished_sandwich=[]
while sandwich_orders:
	tmp=sandwich_orders.pop(0)
	print('I made your '+tmp)
	finished_sandwich.append(tmp)
for sand in finished_sandwich:
	print(sand)

运行结果:


7-9五香肉:
print('Pastrami has been sold')
sandwich_orders=['pastrami','apple sandwich','pastrami','banana sandwich','pastrami','orange sandwich']
while 'pastrami' in sandwich_orders:
	sandwich_orders.remove('pastrami')
print(sandwich_orders)

运行结果:


7-10 梦想的度假胜地:
places=[]
while True:
	tmp=input('If you could visit one place in the world, where would you go\n')
	if tmp=='quit':
		break
	places.append(tmp)
print(places)

运行结果:



猜你喜欢

转载自blog.csdn.net/qq_36325159/article/details/79671621