Python编程:从入门到实践第二版答案(第七章)

 7-1

car = input("which car do you want to lease? ")
print(f"Let me see if i can find you a {car}")

7-2

people = input("How many of you are there? ")
people = int(people)
if people <= 8:
    print("Welcome!")
else:
    print("sorry,We don't have any tables available.")

7-3

num = input("please input a number.And i will tell you if it is a multiple of 10: ")
num = int(num)
if num%10 == 0:
    print("it is a multiple of 10.")
else:
    print("sorry,it is not a multiple of 10.")

7-4

word = ""
while word != "quit":
    word = input("Enter the pizza ingredients you want: ")
    if word != "quit":
        print(f"{word} will be added.")

 7-5

while True:
    age = input("Your age: ")
    if age == "quit":
        break
    age = int(age)
    if age < 3:
        print("You are free.ヽ(✿゚▽゚)ノ")
    elif age < 13:
        print("Your ticket is 13.")
    else:
        print("Your ticket is 15")

7-6

#使用active,另外两项7-4 7-5均有使用
active = True
while active:
    word = input("Enter the pizza ingredients you want: ")
    if word != "quit":
        print(f"{word} will be added.")
    else:
        active = False

7-7

active = True
while active:
    print('1')

 7-8

Sandwich_orders = ['tuna', 'button', 'chicken']
finished_sandwich = []
while Sandwich_orders:
    sandwich = Sandwich_orders.pop()
    print(f"I made your {sandwich} sandwich.")
    finished_sandwich.append(sandwich)
print(finished_sandwich)

7-9

Sandwich_orders = ['pastrami', 'tuna', 'button', 'pastrami', 'chicken', 'pastrami']
print("The pastrami was sold olt.")
while 'pastrami' in Sandwich_orders:
    Sandwich_orders.remove('pastrami')
print(Sandwich_orders)

7-10

active = True
favorite_place = {}
while active:
    name = input("what's your name? ")
    place = input("If you could visit one place in the world,where would you go: ")
    favorite_place[name] = place
    ans = input("Is there anyone next?(yes/no)")
    if ans == "no":
        break
for name, place in favorite_place.items():
    print(f"{name} favorite place is {place}")

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

打赏作者

机务猿

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

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

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

打赏作者

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

抵扣说明:

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

余额充值