您的位置:首页 > 其它

py第七章习题

2018-04-01 10:49 204 查看
#7-1
car = input('Which car do you want?\n')
print('Let me see if I can find you a ' + car + '.')

#7-2
peo = input('How many people comes to have supper? ')
peo = int(peo)
if peo > 8:
print('Sorry, we don`t have so large table.')
else:
print('Welcome!')
print()
#7-3
num = input('Input a num.')
num = int(num)
if num % 10 == 0:
print(str(num) + ' can be divide by ten')
else:
print(str(num) + ' can`t be divide by ten')
print()
#7-4
pizza = []
ing = input('Please input an ingredients what you want to add to your pizza: ')
while ing != 'quit':
pizza.append(ing)
print('We will input the '+ ing +' into your pizza~!')
ing = input('Please input another ingredient what you want to add to your pizza: ')
print('We have add ' + ','.join(pizza) + ' to the pizza')
#7-5
while True:
age = input('How old are you? (input "-1" to quit)\n')
age = int(age)
if age == -1:
break
if age < 3:
print('FREE!')
elif age >= 3 and age <= 12:
print('10$!')
else:
print('15$')
#7-7
while True:
print('HaHaHahahaha23333')

#7-8
sandwich_orders = ['cheese','potato','chicken','beef']
finished_sandwiches = []
while sandwich_orders:
print('I made you ' + sandwich_orders[0] + ' sandwich.')
finished_sandwiches.append(sandwich_orders[0])
del sandwich_orders[0]
print('I have made ' + ' sandwich, '.join(finished_sandwiches) + ' sandwich.')
#7-9
sandwich_orders = ['cheese','potato','chicken','pastrami','pastrami','pastrami','beef']
finished_sandwiches = []
print('Sorry, we have no pastrami already.')
while 'pastrami' in sandwich_orders:
sandwich_orders.remove('pastrami')
while sandwich_orders:
print('I made you ' + sandwich_orders[0] + ' sandwich.')
finished_sandwiches.append(sandwich_orders[0])
del sandwich_orders[0]
print('I have made ' + ' sandwich, '.join(finished_sandwiches) + ' sandwich.')
#7-10
responses = {}
while True:
name = input('What`s your name?\n')
place = input('If you could visit one place in the world, where would you go?\n')

responses[name] = place

repeat = input('Would you like to let another person respond?(yes/no)')
if repeat == 'no':
break

print('-------------Result----------------')
for name,place in responses.items():
print(name.title() + ' want to go to ' + place + '.')
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: