【练习7-1~7-10】Python编程 从入门到实践 第2版

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()}.")
 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值