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

Popular posts from this blog

java - WARN : org.springframework.web.servlet.PageNotFound - No mapping found for HTTP request with URI [/board/] in DispatcherServlet with name 'appServlet' -

android - How to create dynamically Fragment pager adapter -

1111. appearing after print sequence - php -