python 3.x - Global variable as a parameter in a function and not being modified in that function -
so guys have following problem need global variable modified in function in next cycle can go further in range need to
def down(turtlen,posx,posy,up): #function needs modify global variables move = random.randint(0,1) if move == 1: #goes down left posx += 1 posy += 1 turtlen.goto(listpos[up][posx][posy]) else: #goes down right if posy == 0: #keep in range of list posx += 1 posy = 0 turtlen.goto(listpos[up][posx][posy]) else: posx += 1 posy -= 1 turtlen.goto(listpos[up][posx][posy]) def movimiento(n): global posx1 global posy1 global peso1 posx1 = 0 posy1 = 0 peso1 = 0 k in range(n): down(turtle1,posx1,posy1,0)
if want variables global, why use them arguments of function? remove them arguments , declare rather global variable global
statement (as in other function).
Comments
Post a Comment