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 for line in lines: parts = line.split(' ') command = parts[0] distance = int(parts[1]) if command == 'forward': horizontal = horizontal + distance elif command == 'up': depth = depth - distance elif command == 'down': depth = depth + distance print(horizontal*depth)