[Tutor] changing name value with function return

richard kappler richkappler at gmail.com
Tue Oct 30 17:56:09 CET 2012

If I have a variable and send it's value to a function to be modified and
returned, how do I get the function return to replace the original value of
the variable?


import random

x = 50

def rndDelta(x):
    d = random.uniform(-10, 10)
    x = x + d
    return x

When I call rndDelta, it functions as intended, I get a return that is x
adjusted by some random value. This, however, I know does not actually
change x. Let's say I call randDelta(x) and it returns 42.098734087, if I
then type x, I still get 50. I want x to now be 42.098734087.

regards, Richard


sic gorgiamus allos subjectatos nunc
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20121030/7c93f82c/attachment.html>

More information about the Tutor mailing list