import math INPUT_FILE = "input.txt" problems: list[list[int]] = [] with open(INPUT_FILE, 'r') as file: lines: list[str] = file.readlines() problems = [ [] for _ in range(len(lines[0].split())) ] # Prepare all problems for line in lines[:-1]: for i, n in enumerate([ int(n.strip()) for n in line.split() ]): problems[i].append(n) operations: list[str] = lines[-1].split() total = 0 for i, problem in enumerate(problems): operation: str = operations[i] if operation == '+': total += sum(problem) elif operation == '*': total += math.prod(problem) print(f'Total Value: {total}')