【高级编程技术】【作业】【第四周】【1】

教材第7章课后练习

7-1 汽车租赁

car = input('What car would you like to rent?')
print('Let me see if I can find you a '+car.title()+'.')

7-2 餐馆订位

guest_num = int(input('How many guests are having dinner?'))
if guest_num > 8:
    print('There is no empty seat.')
else:
    print('We have enough seats.')

7-3 10的整数倍

number = int(input('Please input a number: '))
if number % 10 == 0:
    print(str(number), 'is an integer multiple of 10.')
else:
    print(str(number), 'is not an integer multiple of 10.')

7-4 比萨配料

while True:
    ingredient = input('Please input an ingredient: ')
    if ingredient == 'quit':
        break
    print('We will add', ingredient, 'into your pizza.')

7-5 电影票

while True:
    age = int(input('Please input your age: '))
    if age < 3:
        print('Free')
    elif age <= 12:
        print('$10')
    else:
        print('$15')

7-6 三个出口

active = True
while active:
    ingredient = input('Please input an ingredient: ')
    if ingredient == 'quit':
        active = False
    else:
        print('We will add', ingredient, 'into your pizza.')

7-7 无限循环

while True:
    print('loop', end='')

7-8 熟食店

sandwich_orders = ['tuna', 'tomato', 'egg', 'ham']
finished_sandwiches = []
while sandwich_orders:
    sandwich = sandwich_orders.pop()
    print('I made your', sandwich, 'sandwich')
    finished_sandwiches.append(sandwich)

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

sandwich_orders = ['tuna', 'tomato', 'egg', 'ham', 'pastrami', 'pastrami', 'pastrami']
finished_sandwiches = []
print('Pastrami has been sold out')
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)

7-10 梦想的度假胜地

places_of_interest = []
while True:
    prompt = 'If you could visit one place in the world, where would you go?'
    place_of_interest = input(prompt)
    if place_of_interest == 'quit':
        break
    places_of_interest.append(place_of_interest)
for place in set(places_of_interest):
    number = places_of_interest.count(place)
    print(number, 'person' if number==1 else 'people', 'would go to', place)
    # 使用了一点Python语法糖
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值