python 从入门到实践第七章课后题

'''7-1'''
car = "请问你需要租约什么品牌的汽车"
cat=''
while cat != 'quit':
cat = input(car)
print("我去查询下,是否还有" + cat + "的汽车。")

'''7-2'''

number = "请问你几位用餐"

while number:
ressen=int(input(number))
if ressen > 8 :
print("没有空座")
else:
print("有空座")


'''7-4'''

pizz = "请输入要想添加的配料"
pizz += "\n请输入quit退出"

while True:
info = input(pizz)
if info == 'quit':
break
else:
print("我们将在您的披萨中添加" + info)



'''7-5'''

mes = "请输入你的年纪"

while mes :
info = int(input(mes))
if info < 3 :
print("免费")
elif info >3 and info <=12 :
print("5元")
else:
print("10元")

"""
"""
'''7-8'''
sandwich_orders = ['s1','s2','s3']
finished_sandwiche = []

while sandwich_orders:#判断条件为真
for i in sandwich_orders:
print("I made your tuna sandwich : " + i)
sandwich_orders.pop()
finished_sandwiche.append(i)
print(finished_sandwiche)

'''7-9'''

sandwich_orders = ['s1','pastrami','s2','pastrami','s3','pastrami']

print("五香牛肉卖完了")
while 'pastrami' in sandwich_orders:#判断一个条件如果在列表中
sandwich_orders.remove('pastrami')#用.remove自定元素名称来删除
print(sandwich_orders)
"""

'''7-10'''

local = {}#定义一个空的字典

names = "请输入你的姓名"
mesinfo = "如果让你去度假你希望去哪里"
Active = True #定义一个标志为真

while Active == True :#给while 条件
name = input(names)
city = input(mesinfo)
local[name] = city#用字典的方法把获取到用户的值写进字典中
cn=input("是否在接受调查 Y/N")
if cn.lower() == 'n':
Active = False#标志设置为假
#print(local)

print("调查的结果为:")
for a , b in local.items():#用for 循环遍历字典
print(a+"希望去"+b)
posted @ 2020-06-22 17:32  网工学搬砖  阅读(228)  评论(0编辑  收藏  举报