直接粗暴 纯逻辑 dic={'A':[-1,0],'W':[0,1],'S':[0,-1],'D':[1,0]} x,y=0,0 arr=input().split(';') for i in arr: if (0<len(i)<=3): if (i[0] in dic): if i[1:].isdecimal():  ...