python初学,确实如果思路到就不难,就只是筛选跟判断的问题,早上起来就给他干了

coordinate = list(input().split(";"))  # 使用“;”进行切片分割出每一个坐标信息,转换成列表
list1 = ["A", "W", "S", "D"]
list2 = []
for strings in coordinate:
    counts = len(strings)
    section = strings[1:counts:]  # 动态切片,将后1/2位字符切出判断是否是数字
    if 2 <= counts <= 3 and strings[0] in list1 and section.isdecimal():
        list2.append(strings)  # 将得到的最终结果追加到列表中
answer = [(0, 0)]
n = 0
for strings in list2:
    counts = len(strings)
    if strings[0] == "A":  # 判断是否为A,x-
        nums = int(strings[1:counts:])  #将数字切出
        tup = (answer[n][0] - nums, answer[n][1])
        answer.append(tup)
        n += 1
    elif strings[0] == "D":  # 判断是否为D,x+
        nums = int(strings[1:counts:])
        tup = (answer[n][0] + nums, answer[n][1])
        answer.append(tup)
        n += 1
    elif strings[0] == "S":  # 判断是否为S,y-
        nums = int(strings[1:counts:])
        tup = (answer[n][0], answer[n][1] - nums)
        answer.append(tup)
        n += 1
    elif strings[0] == "W":  # 判断是否为W,y+
        nums = int(strings[1:counts:])
        tup = (answer[n][0], answer[n][1] + nums)
        answer.append(tup)
        n += 1
print("{},{}".format(answer[-1][0], answer[-1][1]))