Python编程:从入门到实践 练习答案 Chapter07

20211101

7-1
car = input('What kind of car would u like to rent? ')
print('Let me see if I can fond u a ' + car)

7-2
num = int(input('How many people are in your dinner party tonight?: '))
if num > 8:
    print('sorry!there is no more vacant table')
else:
    print('there are still some vacant tables')

7-3
num = int(input('plz input a num:'))
if num % 10 == 0:
    print(str(num) + ' is a multiple of 10.')
else:
    print(str(num) + ' is NOT a multiple of 10.')

7-4
toppings= ''
while toppings != 'quit':
    toppings = input('plz input ur toppings: ')
    print('We will add ' + toppings + ' in pizza.')
 
7-5
age = 0
while True:
    age = input('(enter "quit" to quit)\nplz input ur age:')
    if age == 'quit':
        break
    else:
        age = int(age)
        if(age < 3):
            print('ur ticket is free!')
        elif(3 <= age <= 12):
            print('ur ticket price is $10.')
        else:
            print('ur ticket price is $15.')

7-6
 (1)while_
 toppings = ''
while toppings != 'quit':
    toppings = input('(enter "quit" to quit)\nplz input ur toppings: ')
    if toppings != 'quit':
        print('\nWe will add ' + toppings + ' in pizza.')
        
 (2)activate_
activate = True
while activate:
    toppings = input('(enter "quit" to quit)\nplz input ur toppings: ')
    if toppings == 'quit':
        activate = False
    else:
        print('\nWe will add ' + toppings + ' in pizza.')
        
(3)break_
while True:
    toppings = input('(enter "quit" to quit)\nplz input ur toppings: ')
    if toppings == 'quit':
        break
    print('\nWe will add ' + toppings + ' in pizza.')

7-7
while True:
    print('1')

7-8
sandwich_orders =['veggie', 'grilled cheese', 'turkey', 'roast beef']
finished_sandwiches = []
while sandwich_orders:
    order = sandwich_orders.pop()
    print('I made ur ' + order + ' sandwich')
    finished_sandwiches.append(order)
print(finished_sandwiches)

7-9
sandwich_orders =['pastrami', 'veggie', 'grilled cheese', 'pastrami',\
                  'turkey', 'roast beef', 'pastrami',]
finished_sandwiches = []
print('sorry, pastrami was sell out')
while sandwich_orders:
    order = sandwich_orders.pop()
    if order == 'pastrami':
        continue
    print('I made ur ' + order + ' sandwich')
    finished_sandwiches.append(order)
print(finished_sandwiches)

7-10
places = {}
while True:
    name = input("What's ur name?")
    place = input('If u could visit one place in the world, where would u go?')
    places[name] = place                #(places['name'] = place) is wrong
    polling = input('\nWould u share this polling to others nearby?(yes/no)')
    if polling == 'no':
        break

for n, p in places.items():
    print(n + "'s to go place is " + p)
  
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值