7-1
message=input('您租啥车?')
print(f"Let me see if I can find you a {message}.")
7-2
number=input("请问多少人用餐?")
number=int(number)
if number>8:
print("没有空桌")
else:
print("有空桌")
7-3
number=input('请输一个数字:')
number=int(number)
if number%10==0:
print(f"该数字{number}是十的整数倍")
else:
print(f"该数字{number}不是十的整数倍")
7-4
prompt="请填写你想要的配料,"
prompt+="输入quit结束"
message=""
while message!='quit':
message=input(prompt)
if message!='quit':
print(f"您已添加{message}")
7-5
age=input("请输入你的年龄:")
age=int(age)
if 0 < age < 3:
print('免费')
elif 3<=age<=12:
print("收费10美元")
elif age>12:
print('收费15美元')
else:
print("数据错误")
7-6
prompt="请填写你想要的配料,"
prompt+="输入quit结束"
active=True
while active:
message=input(prompt)
if message=='quit':
break
else:
print(f"您已添加{message}")
7-7
i=0
while i<1:
print('ok')
7-8
sandwich_orders=['lobster','beef','chicken','tuna']
finished_sandwiches=[]
while sandwich_orders:
current_order=sandwich_orders.pop()
print(f"I made your {current_order} sandwich.")
finished_sandwiches.append(current_order)
for i in finished_sandwiches:
print(f"{i.title()} is prepared.")
7-9
sandwich_orders=['lobster','beef','pastrami','chicken','pastrami','tuna','pastrami',]
finished_sandwishes=[]
print("Pastrami is sold out!")
while 'pastrami' in sandwich_orders:
sandwich_orders.remove('pastrami')
finished_sandwishes=sandwich_orders
print(finished_sandwishes)
7-10
responses={}
polling_active=True
while polling_active:
name=input("What's your name?")
response=input("If you could visit one place in the world, where would you go?")
responses[name]=response
repeat=input("Would you like to let another person respond?(yes/no)")
if repeat=='no':
polling_active=False
print('\n---Poll Results---')
for name,response in responses.items():
print(f"{name.title()} would like to visit {response.title()}.")