I had to create the following code to determine how much radiation one person was exposed to in certain amount of time. I created it with a for loop and my answer was 75% correct, I checked on a friend's code that used a while loop and, he had it 100% correct so, my question is Why or what is the difference between then both codes or what am I not doing in the For loop?
I called the function with these lines
radiationExposure(0, 11, 1)
radiationExposure(40, 100, 1.5)
and this is the code:
def f(x):
import math
return 10*math.e**(math.log(0.5)/5.27 * x)
def radiationExposure(start, stop, step):
cuenta = 0.0
Iter = stop - start
for i in range(start,(Iter)+start):
temp = f(i) * step
cuenta += temp
return cuenta
the other code (this is correct):
def f(x):
import math
return 10*math.e**(math.log(0.5)/5.27 * x)
def radiationExposure(start, stop, step):
result = 0
while start < stop:
result += f(start) * step
start += step
return result