## enanoverde 2 years ago My code in Radiation expose 1 is: while final > init: print final result=f(final) print result print '------------------' resultfinal = resultfinal + result*ancho #resultadofinal=0.0 print resultadofinal final=final - 1 return resultfinal But not the same answer in the test: For (0,5,1) ---> Me =34.2839397259 instead of 39.10318784326239 Why ?? please help :P

• This Question is Open
1. enanoverde

sorry : The full code def f(x): import math return 10*math.e**(math.log(0.5)/5.27 * x) def area(inicio, final, ancho): print "de " +str(inicio ) +" a " +str(final) resultadofinal=0.0 while final > inicio: resultado=f(final) resultadofinal = resultadofinal + resultado*ancho final=final - 1 return resultadofinal print area(0, 5,1)

2. Lyrae

I think it should be something like this: def f(x): import math return 10*math.exp((math.log(0.5)/5.27) * x) def area(inicio, final, ancho): print "de " +str(inicio ) +" a " + str(final) resultadofinal = 0 while inicio < final: resultadofinal += f(inicio)*ancho inicio += ancho return resultadofinal print area(0, 5, 1)

3. Lyrae

btw, what course are you taking?

4. jarius327

I had the same issue at first. I did mine slightly different. In the body of the main function I defined the variable exposure to call the function f(start) and multiplied it by step. This returned the amount of radiation exposed times the length of time exposed and saved it to the variable. I then set up a while loop that ran while start is greater than stop minus step. Subtracting one keeps it from adding in the area after the stop point as well so that your answer isn't too large. For each loop the step was added to start (start += step) and then exposure was changed (exposure += f(start) * step) this calculates the next rectangle in the series. When start equals stop it returns the value of exposure. I think the problem with yours getting the wrong answer is similar to how mine was getting one that was too large before I subtracted step from my while loop. but since you are starting at the top stop point and working backwards yours is coming out too small. I hope this helps.