def prime(x): if x == 1: return False for i in range(2,x): if x%i == 0: return False return True def max_value(path): with open(path, 'r') as file: i = 0 sum = 0 maxx = 0 for line in file: for idx, word in enumerate(line.split()): number = int(word) if idx in (i-1, i, i+1) and not prime(number): if maxx < number: maxx = number i = line.split().index(str(maxx)) sum += maxx maxx = 0 return sum print(max_value("text.txt"))