Python 中更改点位置的问题

Problem with changing point position in Python

我正在尝试在 Python 中使用自动增量来简化 "point move",但它无法正常工作(位置保持不变),所以我需要一些帮助

import re

while True:
    m=input(str("How robot should move? (use U,D,L,R to move): "))
if not re.match("^[U,D,L,R]*$", m):
    print("WRONG MOVE! USE -> U,D,L,R")
if re.match("^[U,D,L,R]*$", m):
    moves = list(m.split())
    print(moves)

    x = 0
    y = 1
    position = [x, y]

    for U in moves:
        if U == "U":
            y+=y
        print(position)
        break

我想获得列表中每个符号的位置变化,所以如果输入是 "U,U,U" y 新位置将是 [0,3]

试试这个...

x = list(map(str,input().split(",")))

a = 0
b = 0

for i in x:
    if (i=='U'):
        b+=1
        print(a,b)
    elif (i=='D'):
        b-=1
        print(a,b)
    elif (i=='L'):
        a-=1
        print(a,b)
    elif (i=='R'):
        a+=1
        print(a,b)
    else:
        print("wrong move")
        break;