《Python编程从入门到实践》练习题代码实现第七章

这个博客包含了多个Python编程的实例,包括汽车租赁、餐馆订位、整数倍判断、披萨配料选择、电影票价格计算、熟食店订单处理、五香烟熏牛肉售罄情况以及梦想度假胜地的用户输入处理。通过这些例子,读者可以学习到基本的条件判断、循环控制以及字符串操作等Python编程概念。
摘要由CSDN通过智能技术生成
#7-1 汽车租赁
car=input("which car?")
print(f"Let me see if i can find you a {car}.")

#7-2 餐馆订位
dinner=input("how many people?")
dinner=int(dinner)
if dinner>=8:
    print("sorry,no space.")
else:
    print("ok")

#7-3 10的整数倍
number=input("please give me number")
number=int(number)
if number%10==0:
    print("the number{number} is an integral multiple of 10")
else:
    print("the number{number} is not an integral multiple of 10 ")

#7-4 披萨配料
shuru = "请输入你需要添加的pizza配料:"
shuru +="\n当你输入quit,将停止添加配料:"
pizzas = ""
while pizzas != 'quit':
    pizzas = input(shuru)
    if pizzas != 'quit':
        print("你的比萨添加"+pizzas+"成功\n")
#7-5 电影票
while True:
    age = int(input("请输入用户年龄:"))
    if age < 3:
        print("该用户免费")
    elif 3 <= age < 12:
        print("该年龄段用户收费的是10美元")
    else:
        print("该年龄段用户收费的是15美元")

#7-8 熟食店
sandwich_orders=['egg','banana','apple']
finished_sandwiches={}
while sandwich_orders:
    sandwich = sandwich_orders.pop()
    print("I made your %s sandwich " % sandwich)
finished_sandwiches.append(sandwich)
for i in finished_sandwiches:
    print(i)

#7-9 五香烟熏牛肉卖完了
sandwich_orders = ["a", "b", "pastrami", "c", "pastrami", "d", "pastrami"]
print("五香熏牛肉卖完啦")
while "pastrami" in sandwich_orders:
    sandwich_orders.remove("pastrami")
for i in sandwich_orders:
    print(i)

#7-10 梦想的度假胜地
while True:
    name = input("请输入你的姓名:")
    address = input("你想要去世界上的哪个地方:")
    if address == 'quit' or name == 'quit':
        break
    else:
        print("%s 想要去%s 旅行 " % (name, address))

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值