测评会员优惠活动进行中 · 开通 VIP,有效期内测评不限次 VIP 优惠中 · 测评不限次 立即查看

A23100. 购买餐具学校食堂购买 110个餐具,总共花了 2200元 。已知:盘子25元一个,碗20元一个,勺子10元一个,请列出盘子、碗、勺子各买多少个的所有组合。为解决上述问题,小明编写了以下Python程序,运行结果如后图。请将下面数字序号①②③④⑤⑥处的代码补全:plate = 0 bowl = 0 spoon = 0 price = 0 b =[] for plate in range(1,rou…

填空题 中等

题目描述

购买餐具

学校食堂购买 110个餐具,总共花了 2200元 。已知:盘子25元一个,碗20元一个,勺子10元一个,请列出盘子、碗、勺子各买多少个的所有组合。

为解决上述问题,小明编写了以下Python程序,运行结果如后图。请将下面数字序号①②③④⑤⑥处的代码补全:

plate = 0
bowl = 0
spoon = 0
price = 0
b =[]

for plate in range(1,round(2200/25)):     #盘子数量从少到多
     price =_______①_________#计算盘子价格
     
     for bowl in range(1,_______②_________):    #碗数量从少到多
          price1 = price + bowl * 20           #计算盘子加碗的价格
          
          for spoon in range(1,round(2200/10)):    #勺子数量从少到多
               price2 = price1 + spoon * 10              #计算盘子加碗再加勺子的价格

               if  _______③_________  :           #如果总价等于2200元
                    if  _______④_________== 110:          #如果个数等于110个
                         b. _______⑤_________    ([plate,bowl,spoon,price2])  #将当前数据加入到数组中

for a in _______⑥_________:
     print('盘',a[0],'个;碗',a[1],'个;勺',a[2],'个;价',a[3])    #打印出数组中符合要求的数据

参考答案

plate = 0 bowl = 0 spoon = 0 price = 0 b =[] for plate in range(1,round(2200/25)): #盘子数量从少到多 price = plate * 25 #计算盘子价格 for bowl in range(1,round(2200/20)): #碗数量从少到多 price1 = price + bowl * 20 #计算盘子加碗的价格 for spoon in range(1,round(2200/10)): #勺子数量从少到多 price2 = price1 + spoon * 10 #计算盘子加碗再加勺子的价格 if price2 == 2200: #如果总价等于2200元 if plate+bowl+spoon == 110: #如果个数等于110个 b.append([plate,bowl,spoon,price2]) #将当前数据加入到数组中 for a in b: print('盘',a[0],'个;碗',a[1],'个;勺',a[2],'个;价',a[3]) #打印出数组中符合要求的数据

答案解析

评分标准:

(1)plate * 25 或等效答案;(2分)

(2)round(2200/20) 或等效答案;(3分)

(3)price2 == 2200 或等效答案;(3分)

(4)plate+bowl+spoon 或等效答案;(3分)

(5)append 或等效答案;(3分)  

(6)b 或等效答案。(2分)

上一题 下一题