《Python编程:从入门到实践》课后习题-第7章

7-1 汽车租赁

#7-1 汽车租赁

car = input("请问您需要租赁什么样的汽车?")
print("Let me see if I can find you a " + car)

7-2 餐馆订位

#7-2 餐馆订位

people = input("请问有多少人来用餐?")
number = int(people)
if number >= 8:
    print("不好意思,目前没有空桌。")
else:
    print("目前有空桌。")

7-3 10的整数倍

#7-3 10的整数倍

number = input("请输入一个数:")
number = int(number)

if number % 10 == 0:
    print("\n这个数字是10的整数倍。")
else:
    print("\n这个数字不是10的整数倍。")

7-4 比萨配料

#7-4 比萨配料

prompt = "请输入你想要的比萨配料:"
prompt += "\n输入'quit'来结束程序。"

message = ""
while message != 'quit':
    message = input(prompt)
    if message != 'quit':
        print("我们会在比萨中添加这种配料:" + message)

7-5 电影票

#7-5 电影票

prompt = "\n请输入观众的年龄:"
prompt += "\n输入'quit'来结束程序。"

age = ""
while age != 'quit':
    age = input(prompt)
    if age != 'quit':
        age = int(age)
        if age < 3:
            print("观众免费,票价为0美元。")
        elif age < 12:
            print("票价为10美元。")
        elif age >= 12:
            print("票价为15美元。")
        elif age != 'quit':
            print(age)

7-6 三个出口

#7-6 三个出口1

prompt = "请输入你想要的比萨配料:"
prompt += "\n输入'quit'来结束程序。"

active = True
while active:
    message = input(prompt)
    if message == 'quit':
        active = False
    else:
        print("我们会在比萨中添加这种配料:" + message)
#7-6 三个出口2

prompt = "请输入你想要的比萨配料:"
prompt += "\n输入'quit'来结束程序。"

while True:
    message = input(prompt)
    if message == 'quit':
        break
    else:
        print("我们会在比萨中添加这种配料:" + message)

7-7 无限循环

#7-7 无限循环

x = 1
while x <= 5:
    print(x)

7-8 熟食店

#7-8 熟食店

sandwich_orders = ['tuna','chess','beef']
finished_sandwiches = []
while sandwich_orders:
    current_sandwich = sandwich_orders.pop()
    print("I made your " + current_sandwich + " sandwich.")
    finished_sandwiches.append(current_sandwich)
print("所有的三明治如下:")
for sandwich in finished_sandwiches:
    print(sandwich.title())

7-9 五香烟熏牛肉(pastrami)卖完了

#7-9 五香烟熏牛肉(pastrami)卖完了

sandwich_orders = ['tuna','chess','beef','pastrami','pastrami','pastrami',]
finished_sandwiches = []
print("熟食店的五香烟熏牛肉卖完了。")
while 'pastrami' in sandwich_orders:
    sandwich_orders.remove('pastrami')
while sandwich_orders:
    current_sandwich = sandwich_orders.pop()
    print("I made your " + current_sandwich + " sandwich.")
    finished_sandwiches.append(current_sandwich)
print("所有的三明治如下:")
for sandwich in finished_sandwiches:
    print(sandwich.title())

7-10 梦想的度假胜地

#7-10 梦想的度假胜地

lists = {}
active = True
while active:
    #提示输入被调查者的名字和回答
    name = input("\nWhat's your name?")
    list = input("If you could visit one place in the world, where would you go?")
    #将答案存储在字典中
    lists[name] = list
    repeat = input("Would you like to let another person respond?(yes/no)")
    if repeat == 'no':
        active = False
#调查结束,显示结果
print("\n下面是调查结果:")
for name,list in lists.items():
    print(name + " would like to go " + list + ".")
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值