python:无法获得最终返回

2024-06-16 23:23:21 发布

您现在位置:Python中文网/ 问答频道 /正文

声明:这是一项任务。我尝试了不同的组合来在代码中移动变量[totalExposure],以获得返回值,但失败了。 问题:用递归法找出一段时间内的辐射暴露量。 问题:我可以正确地得到所有的计算结果[我在在线python executor中检查过]但是当进程到达最终返回时,结果是[none]。我不知道为什么我的代码不能返回最终的计算结果。 希望:外面的大师能给我一些线索谢谢。在

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

Tags: 代码声明returntimedefstepmathglobal