0

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?

sdikby
  • 1,383
  • 14
  • 30
andrew fay
  • 95
  • 9

1 Answers1

2

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!
user4815162342
  • 141,790
  • 18
  • 296
  • 355
  • So in this case state and cash will be updated with each iteration of the loop and the function will run with the updated values? Man I had this exact code and overthought it and didn't think it would work like this... Thanks! – andrew fay Sep 23 '17 at 20:16
  • 1
    @andrewfay Exactly. The alternative is to use global variables. – user4815162342 Sep 23 '17 at 20:23