Weak4 Chapter7 Homework

7-2 餐馆定位

i = int(input("请问有多少人用餐? "))
while  i > 0:
    if i > 8:
        print("目前没有空桌")
    else:
        print("目前有空桌")
    i = int(input("请问有多少人用餐? "))

输出结果是:

请问有多少人用餐? 5
目前有空桌
请问有多少人用餐? 10
目前没有空桌

7-3 10的整倍数

i = int(input("请输入一个数字: "))
while  i > 0:
    if i % 10 == 0:
        print(str(i)+"是10的"+str(int(i/10))+"倍")
    else:
        print(str(i)+"不是10的整数倍")
    i = int(input("请输入一个数字: "))

输出结果是:

请输入一个数字: 100
100是10的10倍
请输入一个数字: 59
59不是10的整数倍

7-5 电影票

i = int(input("请输入观众的年龄: "))
while  i >= 0:
    if i < 3:
        print("该观众免费")
    elif i <= 12:
        print("该观众需要支付10美元")
    else:
        print("该观众需要支付15美元")
    i = int(input("请输入观众的年龄: "))

输出结果是:

请输入观众的年龄: 15
该观众需要支付15美元
请输入观众的年龄: 9
该观众需要支付10美元
请输入观众的年龄: 0
该观众免费

7-6 三个出口

active = True
while  active:
    i = input("请输入观众的年龄: ")
    if i == "quit":
        break
    elif int(i) < 3:
        print("该观众免费")
    elif int(i) <= 12:
        print("该观众需要支付10美元")
    else:
        print("该观众需要支付15美元")

输出结果是:

请输入观众的年龄: 15
该观众需要支付15美元
请输入观众的年龄: 9
该观众需要支付10美元
请输入观众的年龄: 0
该观众免费
请输入观众的年龄: quit

7-8 熟食店

sandwich_orders = ['egg mayo','prawn mayo','tuna mayo','bacon lettuce tomato','ham & cheese','roast chicken']
finished_sandwiches = []
while sandwich_orders:
    current = sandwich_orders.pop()
    print("I made your "+current+" sandwich")
    finished_sandwiches.append(current)

print("\nI have these sandwiches:")
for sandwich in finished_sandwiches:
    print(sandwich+" sandwich")

输出结果是:

I made your roast chicken sandwich
I made your ham & cheese sandwich
I made your bacon lettuce tomato sandwich
I made your tuna mayo sandwich
I made your prawn mayo sandwich
I made your egg mayo sandwich

I have these sandwiches:
roast chicken sandwich
ham & cheese sandwich
bacon lettuce tomato sandwich
tuna mayo sandwich
prawn mayo sandwich
egg mayo sandwich

7-9 五香烟熏牛肉卖光了

sandwich_orders = ['egg mayo','prawn mayo','pastrami','tuna mayo','bacon lettuce tomato'
    ,'pastrami','ham & cheese','pastrami','roast chicken']
print("Pastrami has been sold out.")
finished_sandwiches = []

while 'pastrami' in sandwich_orders:
    sandwich_orders.remove('pastrami')

while sandwich_orders:
    current = sandwich_orders.pop()
    finished_sandwiches.append(current)

print("\nI have these sandwiches:")
for sandwich in finished_sandwiches:
    print(sandwich+" sandwich")

输出结果是:

Pastrami has been sold out.

I have these sandwiches:
roast chicken sandwich
ham & cheese sandwich
bacon lettuce tomato sandwich
tuna mayo sandwich
prawn mayo sandwich
egg mayo sandwich
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值