python学习——用户输入和while循环

题目参照《python编程——从入门到实践》第七章习题

7-1

car = input('what kind of car do you want? ')
print('let me see if i can find you a '+car)

7-2

while True:
	age=input('How old are you? ')
	if age=='quit':
		break
	else:
		age=int(age)
		if age<3:
			print('0 dollar')
		elif age>12:
			print('15 dollars')
		else:
			print('10 dollars')
7-5
while True:
	age=input('How old are you? ')
	if age=='quit':
		break
	else:
		age=int(age)
		if age<3:
			print('0 dollar')
		elif age>12:
			print('15 dollars')
		else:
			print('10 dollars')

7-8、7-9

sandwich_orders=['egg','pastrami','pork','pastrami','tuna','pastrami']
finished_orders=[]
while 'pastrami' in sandwich_orders:
	sandwich_orders.remove('pastrami')
print('Pastrami sold out.')
while sandwich_orders:
	sandwich=sandwich_orders.pop()
	print('I made your '+sandwich+' sandwich.')
	finished_orders.append(sandwich)
print(finished_orders)



你可能感兴趣的:(python学习——用户输入和while循环)