7-2 餐馆订位
代码:
num = input("How many people are coming for dinner?")
num = int(num)
if num<=8 :
print("There are empty tables.")
else:
print("None of table is available.")
运行结果:
7-5 电影票
代码:
while True:
age = input("please input your age:")
if age=='quit':
break
age = int(age)
if age<0:
print("The input is invalid.")
elif age<3:
print("You can watch the movie for free.")
elif age<=12:
print("The ticket costs 10 dollars.")
else:
print("The ticket costs 15 dollars.")
运行结果:
7-7无限循环
代码:
while True:
print("infinite")
运行结果:
7-9 patrami卖完了
代码:
sandwich_orders = ['pastrami sandwich','tuna sandwich','pastrami sandwich',
'salmon sandwich','pastrami sandwich','tuna sandwich']
print("Pastrami sandwiches have seld out.")
while 'pastrami sandwich' in sandwich_orders:
sandwich_orders.remove('pastrami sandwich')
print(sandwich_orders)
运行结果: