andrew fay andrew fay - 26 days ago 7
Python Question

Calling a function that returns its updated output python

So I'm completely having a brain fart but I'm attempting to call a function that returns its own updated input in a for loop that has to run 30 times.
I have the for loop part down I'm just not sure how to call the function correctly.

def miniopoloy_turn(state, cash)
return state, cash

so the function returns its updated state and cash values after running, but how would I then run the function again with the updated output inside a for loop?

Answer Source

It sounds like you need to simply store the returned values in local variables and re-run the function as many times as necessary:

# 1. set up initial values
state = ...
cash = ...
# 2. run the function iteratively
for i in xrange(30):
    state, cash = miniopoly_turn(state, cash)
    print state, cash
# 3. profit!