《Python编程——从入门到实践》第七章部分习题解

时间:2021-05-17 19:21:02
# 7-2
num = input('How many people are going to have dinner?')
num = int(num)
if num >= 8:
	print('There is no empty table.')
else:
	print('There are some empty tables.')

# 7-5
while True:
	age = input('How old are you?')
	age = int(age)
	if age < 3 and age >= 0:
		print('Price : Free')
	elif age >= 3 and age < 12:
		print('Price : 10 dollars')
	elif age >= 12:
		print('Price : 15 dollars')

# 7-8
sandwich_orders = ['No.1 sandwich' , 'No.2 sandwich' , 'No.3 sandwich']
finished_sandwich = []
while sandwich_orders:
	current_sandwich = sandwich_orders.pop()
	print('I made your ' + current_sandwich)
	finished_sandwich.append(current_sandwich)
print(finished_sandwich)