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?

3
  • It's spelled cache... Commented Sep 23, 2017 at 20:09
  • 2
    I mean in this case its actually referring to money, like cash... Commented Sep 23, 2017 at 20:10
  • Haha, fair enough. Commented Sep 23, 2017 at 20:25

1 Answer 1

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! 
Sign up to request clarification or add additional context in comments.

2 Comments

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!
@andrewfay Exactly. The alternative is to use global variables.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.