7-1 汽车租赁
message = input("Please enter what kind of car you want to buy: ")
print("Let me see if I can find you a " + message)
输出:
Please enter what kind of car you want to buy: Benz
Let me see if I can find you a Benz
7-2 餐馆订位
num = int(input("How many people will have meals: "))
if num > 8:
print("There is no empty table.")
else:
print("There's an empty table here.")
输出:
How many people will have meals: 9
There is no empty table.
7-3 10的整数倍
num = int(input("please input a num: "))
if num % 10 == 0:
print(str(num) + " is an integer multiple of 10.")
else:
print(str(num) + " is not an integer multiple of 10.")
输出:
please input a num: 34
34 is not an integer multiple of 10.
7-4 比萨配料
msg = "Please enter a pizza ingredient, enter 'quit' to exit the program. Please enter: "
while True:
msg1 = input(msg)
if msg1 == 'quit':
break
else:
print("We'll add " + msg1 + " in pizza.")
输出:
Please enter a pizza ingredient, enter 'quit' to exit the program. Please enter: Tomatoes
We'll add Tomatoes in pizza.
Please enter a pizza ingredient, enter 'quit' to exit the program. Please enter: onion
We'll add onion in pizza.
Please enter a pizza ingredient, enter 'quit' to exit the program. Please enter: Olive oil
We'll add Olive oil in pizza.
Please enter a pizza ingredient, enter 'quit' to exit the program. Please enter: Black pepper
We'll add Black pepper in pizza.
Please enter a pizza ingredient, enter 'quit' to exit the program. Please enter: quit
7-8 熟食店
sandwich_orders = [
"Ham sandwich", "Dried meat floss sandwich", "Bacon sandwich"
]
finished_sandwiches = []
while True:
if len(sandwich_orders) != 0:
sandwich = sandwich_orders.pop()
print("I made your " + sandwich)
finished_sandwiches.insert(0, sandwich)
else:
break
print(finished_sandwiches)
输出:
I made your Bacon sandwich
I made your Dried meat floss sandwich
I made your Ham sandwich
['Ham sandwich', 'Dried meat floss sandwich', 'Bacon sandwich']
7-9 五香烟熏牛肉(pastrami)卖完了
sandwich_orders = [
"Ham sandwich", "pastrami", "Dried meat floss sandwich", "pastrami",
"Bacon sandwich", "pastrami"
]
finished_sandwiches = []
print("The spiced smoked beef in the deli was sold out.")
while "pastrami" in sandwich_orders:
sandwich_orders.remove("pastrami")
print(sandwich_orders)
while True:
if len(sandwich_orders) != 0:
sandwich = sandwich_orders.pop()
print("I made your " + sandwich)
finished_sandwiches.insert(0, sandwich)
else:
break
print(finished_sandwiches)
输出:
The spiced smoked beef in the deli was sold out.
['Ham sandwich', 'Dried meat floss sandwich', 'Bacon sandwich']
I made your Bacon sandwich
I made your Dried meat floss sandwich
I made your Ham sandwich
['Ham sandwich', 'Dried meat floss sandwich', 'Bacon sandwich']