commands = [] with open("input.txt") as f: lines = f.readlines() for line in lines: commands.append(line) horizontal = depth = 0 for command in commands: instruction, amount = command.split(' ') amount = int(amount) if instruction == 'forward': horizontal += amount elif instruction == 'down': depth += amount elif instruction == 'up': depth -= amount part1 = horizontal * depth print(part1) horizontal = depth = aim = 0 for command in commands: instruction, amount = command.split(' ') amount = int(amount) if instruction == 'down': aim += amount elif instruction == 'up': aim -= amount elif instruction == 'forward': horizontal += amount depth += amount*aim part2 = horizontal * depth print(part2)