机器人运动例子

Posted Little Fish

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了机器人运动例子相关的知识,希望对你有一定的参考价值。

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] += 1
actions={
‘up‘ : move_up,
‘left‘:move_left,
‘down‘:move_down,
‘right‘:move_right
}

coord=[0,0]

for move in moves:
actions[move](coord)
print (coord)

以上是关于机器人运动例子的主要内容,如果未能解决你的问题,请参考以下文章