# 7-1 汽车租赁
cars = input("please input you want to get the car: ")
print("Let me see if I can find you a Subaru")
# 7-2 餐馆订位
num = input("please input you want to order how much people: ")
if int(num) >= 8:
print("no empty board")
else:
print("you can come here")
# 7-3 10的整数倍
num = input("please input a number: ")
if int(num) % 10 == 0:
print("This number is a multiple of ten ")
else:
print("This number is not a multiple of ten")
7.2 代码习题
# 7-4 披萨备料
# 版本1
food = input("please ,input you want to get the food: ")
while food != "quit":
print("adding the "+ food)
food = input("please ,input you want to get the food: ")
# 版本2
food = ""
while food != "quit":
food = input("please ,input you want to get the food: ")
if food == "quit":
print("Thank you")
else:
print("adding the "+ food)
# 版本3
active = True
while active:
food = input("please ,input you want to get the food: ")
if food == "quit":
active = False
else:
print("adding the " + food)
# 版本4
while True:
food = input("please ,input you want to get the food: ")
if food == "quit":
break
else:
print("adding the " + food)
7.3代码习题
# 7-8 熟食店
sandwich_order = ["tomatoes", "han", "beef"]
finished_sandwich = []
while sandwich_order:
sandwich = sandwich_order.pop()
print("I made you " + sandwich + " sandwich")
finished_sandwich.append(sandwich)
for i in finished_sandwich:
print(i)
print()
# 7-9 五香熏牛肉
sandwich_order = ["tomatoes", "pastrami", "han", "pastrami", "beef", "pastrami"]
finished_sandwich = []
print("The pastrami has sell out")
while "pastrami" in sandwich_order:
sandwich_order.remove("pastrami")
print(sandwich_order)
while sandwich_order:
sandwich = sandwich_order.pop()
finished_sandwich.append(sandwich)
for i in finished_sandwich:
print(i)