Python编程:从入门到实践的动手试一试答案(第七章)

#7-1 汽车租赁
car = input("What car do you need: ")
print('Let me see if I can find you a' + car)
 
 
  • 1
  • 2
  • 3
#7-2 餐馆订位
inquiry = input("Excuse me, how many people to have dinner: ")
if int(inquiry) > 8:
    print('没空桌')
else:
    print('有空桌')

 
 
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
#7-3 10的整数倍
inquiry = input("请输入一个数字: ")
if int(inquiry) % 10 == 0:
    print('是10的整数倍')
else:
    print('不是10的整数倍')
 
 
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
#7-4 比萨配料
active = True
while active:
    inquiry = input("请输入你想要的披萨配料: ")
    if inquiry == 'quit':
        active = False
    else:
        print('我们将加入该配料')
 
 
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
#7-5 电影票
active = True
while active:
    age = input("请输入你年龄: ")
    if int(age) < 3:
        print('免费')
    elif int(age) < 12:
        print('$10')
    else:
        print('$15')
 
 
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
#7-6 三个出口
active = True
while active:
    inquiry = input("请输入你想要的披萨配料: ")
    if inquiry == 'quit':
        break
    else:
        print('我们将加入该配料')
 
 
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
#7-7 无限循环
active = True
while active:
     print('hello world')
 
 
  • 1
  • 2
  • 3
  • 4
#7-8 熟食店
sandwich_orders = ['apple','banana','milk']
finished_sandwiches = []

while sandwich_orders:
    sandwich = sandwich_orders.pop()
    print('I made your ' + sandwich + 'sandwich')
    finished_sandwiches.append(sandwich)
print(finished_sandwiches)
 
 
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
#7-9 五香烟熏牛肉(pastrami)卖完了
sandwich_orders = ['apple','pastrami','banana','pastrami','milk','pastrami']
finished_sandwiches = []
print('五香烟熏牛肉(pastrami)卖完了')
while 'pastrami' in sandwich_orders:
    sandwich_orders.remove('pastrami')
while sandwich_orders:
    sandwich = sandwich_orders.pop()
    print('I made your ' + sandwich + 'sandwich')
    finished_sandwiches.append(sandwich)
print(finished_sandwiches)
 
 
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
#7-10 梦想的度假胜地
places = {}
polling_active = True
while polling_active:
    name = input("\nWhat is your name? ")
    response = input("If you could visit one place in the world, where would you go?")
    places[name] = response
    repeat = input("Would you like to let another person respond? (yes/ no) ")
    if repeat == 'no':
         polling_active = False

print("\n--- Poll Results ---")

for name, response in places.items():
      print(name + " would like to  " + response + ".")
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值