import os dir = os.path.dirname(os.path.abspath(__file__)) with open(os.path.join(dir, './input.txt'), 'r') as input_file: lines = input_file.readlines() horizontal = 0 depth = 0 aim = 0 for line in lines: parts = line.split(' ') command = parts[0] distance = int(parts[1]) if command == 'forward': horizontal = horizontal + distance depth = depth + (aim * distance) elif command == 'up': aim = aim - distance elif command == 'down': aim = aim + distance print(horizontal*depth)