声明:这是一个赋值。我尝试了不同的组合来将变量 [totalExposure] 移动到我的代码中以获得返回但失败了。 问题:使用递归查找一段时间内的辐射暴露。 问题:我可以正确地得到所有的计算[我在在线python执行器中检查过]但是当过程到达最终返回时,结果是[无]。我不知道为什么我的代码不能返回最终的计算结果。 希望:那里的一些大师可以给我一些线索谢谢。
global totalExposure
totalExposure=0
def f(x):
import math
return 10*math.e**(math.log(0.5)/5.27 * x)
def radiationExposure(start, stop, step):
time=(stop-start)
newStart=start+step
if(time!=0):
radiation=f(start)*step
radiationExposure(newStart, stop, step)
global totalExposure
totalExposure+=radiation
else:
return totalExposure
请您参考如下方法:
为了执行递归,您必须在 radiationExposure 中返回调用:
return radiationExposure(newStart, stop, step)
