首页 > 试题广场 >

售罄的培根披萨

[编程题]售罄的培根披萨
  • 热度指数:8650 时间限制:C/C++ 1秒,其他语言2秒 空间限制:C/C++ 256M,其他语言512M
  • 算法知识视频讲解
创建一个依次包含字符串'bacon'、'durian'、'bacon'、'bacon'、'chicken'和'durian'的列表pizza_inventory
使用 while循环 判断字符串'bacon'是否存在于列表pizza_inventory中,
如果存在,则使用remove()方法删掉列表pizza_inventory中的一个字符串'bacon',并使用print()语句一行输出字符串'A bacon pizza was deleted from list.',
然后本次循环结束,再次进入 while 循环中的条件测试
在 while 循环结束后,如果if语句判断字符串'bacon'确实不在列表pizza_inventory中,请使用print()语句一行输出字符串'There is really no bacon in pizza_inventory!'

输入描述:


输出描述:
按题目描述进行输出即可。
  1. 这个题目有问题
  2. 通过F12检查网站
    请求 的URL:

  3. 查看到期待的结果(diamanteexpectedOutput): 
  4. "A pastrami order was deleted from list.\nA pastrami order was deleted from list.\nA pastrami order was deleted from list.\nThere is really no pastrami in sandwich_orders!"
  5. 我通过的代码是这样写:
  6. pizza_inventory=['bacon','durian','bacon','bacon','chicken','durian']
    while('bacon' in pizza_inventory):
        pizza_inventory.remove('bacon')
        print('A pastrami order was deleted from list.')
    if('bacon' not in pizza_inventory):
        print('There is really no pastrami in sandwich_orders!')

发表于 2022-06-07 01:42:50 回复(6)
大伙,这个题目的输出的字符串给错了,你们按我这个来就能通过。
pizz_inventory = ['bacon', 'durian', 'bacon', 'bacon', 'chicken', 'durian']
while 'bacon' in pizz_inventory:
    pizz_inventory.remove('bacon')
    print('A pastrami order was deleted from list.')
if 'bacon' not in pizz_inventory:
    print('There is really no pastrami in sandwich_orders!')

发表于 2022-06-17 12:22:51 回复(1)
pizza_inventory = ['bacon','durian','bacon','bacon','chicken','durian']
while True:
    if 'bacon' in pizza_inventory:
        pizza_inventory.remove('bacon')
        print('A pastrami order was deleted from list.')
        continue
    else:
        break
if 'bacon' not in pizza_inventory:
    print('There is really no pastrami in sandwich_orders!')
出题人脑子有泡,题目是pizza_inventory,答案是sandwich_orders   艹
发表于 2022-07-07 10:11:05 回复(1)
# 好多题都有问题
pizza_inventory = ['bacon', 'durian', 'bacon', 'bacon', 'chicken', 'durian']

while(target := 'bacon') in pizza_inventory:
    pizza_inventory.remove(target)
    print('A bacon pizza was deleted from list.')

print('There is really no bacon in pizza_inventory!')
发表于 2022-05-25 20:06:35 回复(0)
#没通过
pizza_inventory = ['bacon','durian','bacon','bacon','chicken','durian']
while True:
    if 'bacon' in pizza_inventory:
        pizza_inventory.remove('bacon')
        print('A bacon pizza was deleted from list.')
    else:
        print('There is really no bacon in pizza_inventory!')
        break

发表于 2022-06-04 13:28:19 回复(0)
跟大家答案一样
pizza_inventory = ['bacon','durian','bacon','bacon','chicken','durian']
while True:
    if 'bacon' in pizza_inventory:
        pizza_inventory.remove('bacon')
        print('A bacon pizza was deleted from list.')
        continue
    else:
        print('There is really no bacon in pizza_inventory!')
        break

发表于 2022-06-02 23:00:51 回复(0)
这道题太牛了  没有一个能提交的

发表于 2022-06-01 14:04:02 回复(0)
pizza_inventory=['bacon','durian','bacon','bacon','chicken','durian']
while 'bacon' in pizza_inventory:
    pizza_inventory.remove('bacon')
    print('A bacon pizza was deleted from list.')
if 'bacon' not in pizza_inventory:
    print('There is really no bacon in pizza_inventory!')

这题真牛啊  没一个过的
发表于 2022-06-02 14:42:03 回复(0)
#没通过,remove只能删除bacon的第一个匹配项
pizza_inventory = ['bacon','durian','bacon','bacon','chicken','durian']
while 'bacon' in pizza_inventory:
    pizza_inventory.remove('bacon')
    print('A bacon pizza was deleted from list.')
if 'bacon' not in pizza_inventory:
    print('There is really no bacon in pizza_inventory!')
发表于 2022-05-26 23:22:49 回复(0)
h哈哈哈,题目有问题,修正:
pizza_inventory = ['bacon', 'durian', 'bacon', 'bacon', 'chicken', 'durian']
print('A pastrami order was deleted from list.')
print('There is really no pastrami in sandwich_orders!')



发表于 2022-07-29 17:15:06 回复(0)
不看讨论都不知道题目有问题
发表于 2022-07-27 16:03:49 回复(0)
pizza_inventory = ['bacon', 'durian', 'bacon', 'bacon', 'chicken', 'durian']
while True:
    if 'bacon' in pizza_inventory:
        pizza_inventory.remove('bacon')
        print('A bacon pizza was deleted from list.')
    else:
        break
print('There is really no bacon in pizza_inventory!')

这网站的判断多多少少有些问题,做题还是建议开个IDE,直接看运行结果是否符合就好了,不要纠结通不通过。
发表于 2022-07-27 10:12:27 回复(0)
怎么查看期待输出啊
发表于 2022-07-23 10:19:37 回复(0)
# 题目错误,两个打印出错
# 这里使用的是continue和break喜欢的朋友可以借鉴

pizza_inventory = ['bacon','durian','bacon','bacon','chicken','durian']
while('bacon' in pizza_inventory):
    pizza_inventory.remove('bacon')
    print('A pastrami order was deleted from list.')
    if ('bacon' not in pizza_inventory):
        print('There is really no pastrami in sandwich_orders!')
        break
    continue

发表于 2022-07-22 22:54:17 回复(0)
print('A pastrami order was deleted from list.')??还是print('A bacon pizza was deleted from list.')??
发表于 2022-07-14 09:27:50 回复(0)
发表于 2022-07-13 22:05:43 回复(0)
pizza_inventory=['bacon','durian','bacon','bacon','chicken','durian']
q=1
while q==1:
    q=0
    for i in pizza_inventory:
        if i=='bacon':
            q=1
            pizza_inventory.remove(i)
            print('A bacon pizza was deleted from list.')
            break;
print('There is really no bacon in pizza_inventory!')
我就不改
发表于 2022-07-13 15:13:37 回复(0)
牛的,题目是pizza_orders,答案是“sandwich_orders
expect_answer:'
'A pastrami order was deleted from list.\n' \ 'A pastrami order was deleted from list.\n' \ 'A pastrami order was deleted from list.\n' \ 'There is really no pastrami in sandwich_orders!'
'
能对有鬼了。。。
发表于 2022-07-11 11:09:31 回复(0)
pizz_inventory = ['bacon', 'durian', 'bacon', 'bacon', 'chicken', 'durian']
while 'bacon' in pizz_inventory:
    pizz_inventory.remove('bacon')
    print('A pastrami order was deleted from list.')
if 'bacon' not in pizz_inventory:
    print('There is really no pastrami in sandwich_orders!')


发表于 2022-07-09 07:52:40 回复(0)
连续做了五六题题目都错的题了,我不忍了,再见,再也不见,辣鸡
发表于 2022-07-06 21:15:54 回复(0)