位置计算与路线记录
x0y0route[(0,0)]#起点坐标cmd input(请输入移动指令: )#input表示输入指令cmd表示变量for c in cmd:if c“F”:yy1if c“B”:yy-1if c “L”:xx-1if c “R”:xx1route.append((x,y))print(“最终坐标”,x,y)print(“一共走了”,len(cmd),“步”)if x0 and y0:print(“已回到起点”)else:print(“未回到起点”)#把坐标转化成字符串str_list [str(point) for point in route ]#用→连接path “→”.join(str_list)print(“行走路线:”,path)