Python Word问题
这个词的问题是:制作一件物品只需要2分7秒。不幸的是,143件产品生产完成后,制造商必须冷却5分13秒才能继续生产。编写一个程序,计算制造给定数量的产品所需的时间 测试编号为1340项Python Word问题,python,Python,这个词的问题是:制作一件物品只需要2分7秒。不幸的是,143件产品生产完成后,制造商必须冷却5分13秒才能继续生产。编写一个程序,计算制造给定数量的产品所需的时间 测试编号为1340项 numItems = 1340 produceitem = 2 * 60 + 7 #2 minutes and 7 seconds cooldown = 5 * 60 + 13 #5 minutes and 13 seconds items_before_delay = 143 productiontime =
numItems = 1340
produceitem = 2 * 60 + 7 #2 minutes and 7 seconds
cooldown = 5 * 60 + 13 #5 minutes and 13 seconds
items_before_delay = 143
productiontime = 0
if numItems <= 143:
productiontime = produceitem * numItems
if numItems > 143:
productiontime = (produceitems * numItems) - (numItems / items_before_delay * cooldown)
print str(productiontime) + "seconds"
numItems=1340
produceitem=2*60+7#2分7秒
冷却时间=5*60+13#5分13秒
延迟前的项目=143
生产时间=0
如果numItems 143:
生产时间=(生产项目*numItems)-(numItems/items\u延迟*冷却前)
打印str(生产时间)+“秒”
测试编号的输出应为172997秒,但我的程序将其输出为167363秒
有人能告诉我我能做些什么来改善这一点吗?你在减去冷却时间,而不是增加冷却时间。就这样 因此,改变这一点:
productiontime = (produceitems * numItems) - (numItems / items_before_delay * cooldown)
……为此:
productiontime = (produceitems * numItems) + (numItems / items_before_delay * cooldown)
然而,当我们在这里时:
- 您定义了
,但使用了produceitem
。如果这真的有效,可能是因为您在交互式解释器中很幸运,已经定义了produceitems
produceitems
- 如果要在延迟之前定义一个常数
,不要直接使用数字143,请在延迟之前使用items\u
items\u
- 如果a b:,则不要执行
;只需将第二个更改为
其他:
- 事实上,您根本不需要
。如果if
numItems thx那么多!我一定会听从你的建议!1340只是一个测试数字。我要将其更改为原始输入:)@abarnert@user2006236:是的,我想在你的实际程序中要么是
要么是int(raw_input())
。int(sys.argv[1])
num_items = 1340 produce_item = 2 * 60 + 7 #2 minutes and 7 seconds cooldown = 5 * 60 + 13 #5 minutes and 13 seconds items_before_delay = 143 total_cooldown = num_items // items_before_delay * cooldown production_time = (produce_item * num_items) + total_cooldown print '{} seconds'.format(production_time)