Ответ:
def srez(S):
N = S[S.find("(")+1:S.find(")")]
if N == "":
N = 1
else:
N = int(N)
S = S[:S.find("(")+1] + S[S.find(")"):]
if S[0:4] == " ":
S = S[4:]
Srez = [N,S,True]
else:
Srez = [N,S,False]
return(Srez)
def move(srez,coord):
if srez[2] == False:
kef.forK = 1
comm = ["move_right()","move_left()","move_up()","move_down()","for k in range():"]
if srez[1] == comm[0]:
coord[0] += srez[0]*kef.forK
return([coord[0],coord[1]])
elif srez[1] == comm[1]:
coord[0] -= srez[0]*kef.forK
return([(coord[0]),coord[1]])
elif srez[1] == comm[2]:
coord[1] += srez[0]*kef.forK
return([coord[0],coord[1]])
elif srez[1] == comm[3]:
coord[1] -= srez[0]*kef.forK
return([coord[0],(coord[1])])
elif srez[1] == comm[4]:
kef.forK = srez[0]
return([coord[0],coord[1]])
def dosrez(S,N):
S1 = S[:-1]+str(N)+")"
return(S1)
def cout(coord,doing,comm):
x = coord[0]
y = coord[1]
if doing > 2 or (x*y==0 and doing == 2):
if x > 1:
S = comm[0]
S = dosrez(S,x)
print(S)
elif x < -1:
S = comm[1]
S = dosrez(S,-x)
print(S)
elif x == 1:
print(comm[0])
elif x == -1:
print(comm[1])
if y > 1:
S = comm[2]
S = dosrez(S,y)
print(S)
elif y < -1:
S = comm[3]
S = dosrez(S,-y)
print(S)
elif y == 1:
print(comm[2])
elif y == -1:
print(comm[3])
class kef():
forK = 1
coord = [0,0]
doing = []
comm = ["move_right()","move_left()","move_up()","move_down()","for k in range():"]
while True:
S = str(input())
if len(S) > 0:
if S[0] == "#":
break
doing.append(S)
for i in doing:
Srez1 = srez(i)
coord = move(Srez1,coord)
cout(coord,len(doing),comm)