《Python编程从入门到实践》第7章习题

7-1

car=input('What kind of car do you want to rent?')
print('Let me see if I can find you a '+car+' .')
What kind of car do you want to rent?Subaru
Let me see if I can find you a Subaru .

7-2

i=input('How many people are there in your party?')
if int(i) >= 8:
    print('I am sorry we do not have a vacant table.')
else:
    print('Ok,we have some vacant tables.')
How many people are there in your party?10
I am sorry we do not have a vacant table.

How many people are there in your party?3
Ok,we have some vacant tables.

7-3

i=input('请输入一个数字:')
if int(i)%10 :
    print('这个数不是10的整数倍。')
else:
    print('这个数是10的整数倍。')
请输入一个数字:11
这个数不是10的整数倍。

请输入一个数字:50
这个数是10的整数倍。

7-4

while True:
    food_ingredient=input('请输入一种披萨配料:')
    if food_ingredient != 'quit':
        print('我们会在披萨中加入'+food_ingredient+'。')
    else:
        break
请输入一种披萨配料:salt
我们会在披萨中加入salt。
请输入一种披萨配料:sugar
我们会在披萨中加入sugar。
请输入一种披萨配料:quit

7-5

while True:
    age=input('请输入您的年龄:')
    if age != 'quit':
        if int(age) < 3:
            print('免费!')
        elif int(age) >= 3 and int(age) < 12:
            print('票价为10美元')
        else:
            print('票价为15美元')
    else:
        break
请输入您的年龄:50
票价为15美元
请输入您的年龄:2
免费!
请输入您的年龄:10
票价为10美元
请输入您的年龄:quit

7-6

active=True
while active:
    age=input('请输入您的年龄:')
    if age != 'quit':
        if int(age) < 3:
            print('免费!')
        elif int(age) >= 3 and int(age) < 12:
            print('票价为10美元')
        else:
            print('票价为15美元')
    else:
        active=False
请输入您的年龄:10
票价为10美元
请输入您的年龄:quit

7-7

i=1
while 1:
    print(i)

7-8

sandwich_orders=['A_sandwich','B_sandwich','C_sandwich']
finished_sandwich=[]
while sandwich_orders:
    sandwich=sandwich_orders.pop()
    finished_sandwich.append(sandwich)
    print('I made your '+sandwich+' !')
print('All sandwiches have been made.')
for sandwich in finished_sandwich:
    print(sandwich)
I made your C_sandwich !
I made your B_sandwich !
I made your A_sandwich !
All sandwiches have been made.
C_sandwich
B_sandwich
A_sandwich

7-9

print('All the pastrami is sold out.')
sandwich_orders=['pastrami','A_sandwich','pastrami','B_sandwich','pastrami','C_sandwich']
finished_sandwich=[]
while sandwich_orders:
    sandwich=sandwich_orders.pop()
    if sandwich != 'pastrami':
        finished_sandwich.append(sandwich)
        print('I made your '+sandwich+' !')
    else:
        continue
print('All sandwiches have been made.')
for sandwich in finished_sandwich:
    print(sandwich)
All the pastrami is sold out.
I made your C_sandwich !
I made your B_sandwich !
I made your A_sandwich !
All sandwiches have been made.
C_sandwich
B_sandwich
A_sandwich

7-10

while True:
    scenic_spots = input('If you could visit one place in the world,where would you go?')
    if scenic_spots != 'quit':
        print('I want to go to '+scenic_spots+'.')
    else:
        break

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

长得丑就要多读书

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值