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)
Python编程:从入门到实践 练习答案 Chapter07
最新推荐文章于 2024-11-02 16:28:26 发布