0

I want to use the function f in the function radiationExposure, but this code return nothing.

def f(x):
    import math
    return 10*math.e**(math.log(0.5)/5.27*x)


def radiationExposure(start, stop, step):    
    if start < 0 or stop < start or step < 0:
        print("Invalid inputs!")
    else:
        result = 0 # Total radiation exposure area
        for i in range(start, stop + 1):
            result += f(i)*step
        return result


radiationExposure(5, 10, 1)
4
  • 2
    Do you mean it returns nothing, or prints nothing? Commented Oct 26, 2014 at 11:12
  • it just returns nothing. it did not print out anything Commented Oct 26, 2014 at 11:31
  • Don't use local imports, they make it harder to understand your code and are usually only used to break cyclic dependencies (a bad thing to have), or to make conditional imports based e.g. on operating-system or availability of extension modules. No need for you to use them. Commented Oct 26, 2014 at 11:48
  • FWIW, it's better to do math.exp(num) than math.e**num. Commented Oct 26, 2014 at 12:44

1 Answer 1

4

When you run a Python script, it will not auto-echo the result. Your code runs fine, but you need to explicitly print the result:

print(radiationExposure(5, 10, 1))

Your script, when run, will now print 22.9424104106.

Sign up to request clarification or add additional context in comments.

2 Comments

but I thought my radiationExposure function will return a result?
It does return a result. But you are not doing anything with it. You need to print it, as Martijn showed you.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.