Python编程之入门到实践 第七章习题代码

7.1代码习题

# 7-1 汽车租赁
cars = input("please input you want to get the car: ")
print("Let me see if I can find you a Subaru")

# 7-2 餐馆订位
num = input("please input you want to order how much people: ")
if int(num) >= 8:
    print("no empty board")
else:
    print("you can come here")

# 7-3 10的整数倍
num = input("please input a number: ")
if int(num) % 10 == 0:
    print("This number is a multiple of ten ")
else:
    print("This number is not a multiple of ten")

 7.2 代码习题

# 7-4 披萨备料
# 版本1
food = input("please ,input you want to get the food: ")
while food != "quit":
    print("adding the "+ food)
    food = input("please ,input you want to get the food: ")

# 版本2
food = ""
while food != "quit":
    food = input("please ,input you want to get the food: ")
    if food == "quit":
        print("Thank you")
    else:
        print("adding the "+ food)

# 版本3
active = True
while active:
    food = input("please ,input you want to get the food: ")
    if food == "quit":
        active = False
    else:
        print("adding the " + food)

# 版本4

while True:
    food = input("please ,input you want to get the food: ")
    if food == "quit":
        break
    else:
        print("adding the " + food)



7.3代码习题

# 7-8 熟食店
sandwich_order = ["tomatoes", "han", "beef"]
finished_sandwich = []
while sandwich_order:
    sandwich = sandwich_order.pop()
    print("I made you " + sandwich + " sandwich")
    finished_sandwich.append(sandwich)
for i in finished_sandwich:
    print(i)
print()

# 7-9 五香熏牛肉
sandwich_order = ["tomatoes", "pastrami", "han", "pastrami", "beef", "pastrami"]
finished_sandwich = []
print("The pastrami has sell out")
while "pastrami"  in sandwich_order:
    sandwich_order.remove("pastrami")
print(sandwich_order)
while sandwich_order:
    sandwich = sandwich_order.pop()
    finished_sandwich.append(sandwich)
for i in finished_sandwich:
    print(i)




  • 11
    点赞
  • 7
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值