prog6_22.py

position = 0
direction = 1  # 1が昇り、-1が降り
while True:
    move = input("ロボットの動作?")
    if move == "":
        break
    if move == "-":
        print("向きを変えます")
        direction = -direction
        continue
    move = int(move)
    position += direction * move
    if direction > 0:
        action = "昇って"
    else:
        action = "降りて"
    print(f"{move}段{action}{position}段目にきました")
print("終了!")

# プログラム6-22(ロボットの階段昇降)