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)

運行結果:



發佈了33 篇原創文章 · 獲贊 0 · 訪問量 9011
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章