damaged = 0 for i in range(5006): if i % 10 == 9: continue if i % 6 == 5: damaged += 1 continue if i == 5006-1: continue # 如果代码执行到这里,说明这个暖瓶没有损坏,也没有到达 10 个暖瓶的边界,所以需要加上运费。 total += 0.5 if total == 1332: print("损坏的暖瓶个数为:", damaged) else: print("计算有误,总运费为:", total)

用python写:某运输队为超市运送暖瓶 500 箱每箱装有 6 个暖瓶。已知每 10 个暖瓶的运费为 5 元损坏一个不但不给运费还要赔 10 元运后结算时运输队共得 1332 元的运费。编程输出损坏暖瓶的个数。注意:用循环语句实现

原文地址: https://www.cveoy.top/t/topic/cu24 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录