python从入门到实践第7章习题

在这里插入图片描述

7-1 汽车租赁

type=input("What kind of car do you want:")
print('\nLet me see if I can find you a ' + type)

7-2 餐馆订位

number = int(input('How many people have dinner :'))
if number > 8:
    print('\nsorry,There is no table in free')
else:
    print('OK,I am waiting for you')
number=int(input())

7-3 10的整数倍

num=int(input('输入数字:'))
if num%10==0:
    print(str(num) + "是10的倍数")
else:
    print(str(num)+"不是10的倍数")

在这里插入图片描述
7-4 方法一 比萨配料

prompt="请输入配料"
prompt+='\n想加入的配料:'
while True:
        message=input(prompt)
        if message=="quit":
            break
        else:
            print("\n添加"+message)
方法二 比萨配料
print("请输入配料,quit退出")
ingredients=""
while ingredients != "quit":
    ingredients = input ("想在pizza中加啥:")
    if ingredients != "quit":
        print("加入"+ ingredients)

7-5 方法一 电影票

years = '\nPlease input your years old:'
years += "\n(Enter 0 when you are finished)"
while True:
    old = int(input(years))
    if old == "0":
        break
    elif old < 3:
        cost = 'free'
    elif old < 12:
        cost = 10
    else:
        cost = 15
    print('\nThe price of your ticket is ' + str(cost))

# 方法二电影票
print("请输入年龄,计算票价,*退出")
age=""

while age !="*":
    age=input("你多大:")
    if age != "*":
        age=int(age)
        if age <0:
            print("请重新输入")
        elif age>=0 and age<3:
            price=0
        elif age>=3 and age<18:
            price=10
        elif age >18:
            price=15
        print('You admission cost is '+ price.__str__()+'$.')
print('请输入年龄,计算票价,*退出')

7-6 三个出口

age = ''
while True:
    age = input("您好,请问您的年龄是多少:")
    if age == 'qiut':
        print("qiut")
        break
    elif int(age) < 0:
        print("你不是人,请回你的火星去。")
    elif int(age) < 3:
        print("您好,您免费哦!")
    elif int(age) <= 12:
        print("您好,收费金额为:10元")
    elif int(age) > 12:
        print("您好,收费金额为:15元")

7-7无线循环

a=1
while True:
     print(a)
     a=2
     a+=1

在这里插入图片描述

# 7-8 熟食店
sandwich_orders =["A","B","C"]
finished_sandwiches =[]
while sandwich_orders:
    介质=sandwich_orders.pop()
    finished_sandwiches.append(介质)
# print('finished_sandwiches')
for sandwich in finished_sandwiches:
    print(sandwich)
#7-9 五香烟熏牛肉
sandwich_orders =["A","五香牛肉","C","五香牛肉","B","五香牛肉"]
while "五香牛肉" in sandwich_orders:
    sandwich_orders.remove('五香牛肉')
for sandwich in sandwich_orders:
    print(sandwich)
#7-10 梦想的度假胜地
namesCitys = {}
verdict = True
while verdict:
    name = input("您好,您叫什么名字?(输入'qiut即结束')")
    if name == 'qiut':
        break
    citys = input("如果你能去到世界上的一个地方,你会去哪里(输入'qiut即结束')")
    if citys == 'qiut':
        break
    namesCitys[name] = citys
print(namesCitys)
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值