moves=[‘up‘,‘left‘,‘down‘,‘right‘,‘right‘] def move_up(x): x[1]+=1 def move_left(x): x[1]-=1 def move_down(x): x[1] -= 1 def move_right(x): x[1] += 1actions={ ‘up‘ : move_up, ‘left‘:move_left, ‘down‘:move_down, ‘right‘:move_right } coord=[0,0] for move in moves: actions[move](coord) print (coord)
时间: 2024-10-07 15:59:55