Проблема в replace
c = input()
c.split('\n')
axisX = 0
axisY = 0
for s in c:
if ("move_up" in s):
if (s != "move_up()"):
axisY += int(s.replace("move_up(", "").replace(")", ""))
else:
axisY += 1
elif ("move_down" in s):
if (s != "move_down()"):
axisY -= int(s.replace("move_down(", "").replace(")", ""))
else:
axisY -= 1
elif ("move_left" in s):
if (s != "move_left()"):
axisX -= int(s.replace("move_left(", "").replace(")", ""))
else:
axisX -= 1
elif ("move_right" in s):
if (s != "move_right()"):
axisX += int(s.replace("move_right(", "").replace(")", ""))
else:
axisX += 1
elif ("for k in range" in s and "move_up" in s+1):
if (s+1 != "move_up()"):
axisY += int(s.replace("for k in range(", "").replace(")", "")) * int(s.replace("move_up(", "").replace(")", ""))
else:
axisY += int(s.replace("for k in range(", "").replace(")", ""))
elif ("for k in range" in s and "move_down" in s+1):
if (s+1 != "move_up()"):
axisY -= int(s.replace("for k in range(", "").replace(")", "")) * int(s.replace("move_up(", "").replace(")", ""))
else:
axisY -= int(s.replace("for k in range(", "").replace(")", ""))
elif ("for k in range" in s and "move_right" in s+1):
if (s+1 != "move_up()"):
axisX += int(s.replace("for k in range(", "").replace(")", "")) * int(s.replace("move_up(", "").replace(")", ""))
else:
axisX += int(s.replace("for k in range(", "").replace(")", ""))
elif ("for k in range" in s and "move_left" in s+1):
if (s+1 != "move_up()"):
axisX -= int(s.replace("for k in range(", "").replace(")", "")) * int(s.replace("move_up(", "").replace(")", ""))
else:
axisX -= int(s.replace("for k in range(", "").replace(")", ""))
print(axisX, axisY)
if (axisX != 0):
if (axisX < 0):
print(f"move_left({axisX * -1})")
else:
print(f"move_right({axisX})")
if (axisY != 0):
if (axisY < 0):
print(f"move_down({axisY * -1})")
else:
print(f"move_up({axisY})")
Я написал print(axisX, axisY) для проверки. Выводит 0 0. Дело в replace. Как мне получить число из функции тогда? К примеру move_up(8) я должен получить 8.
