《Python编程 从入门到实践》第七章习题选做

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']
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值