Facebook
From Sabiha İffet Göycıncık, 1 Month ago, written in Python.
Embed
Download Paste or View Raw
Hits: 41
  1. def prime(x):
  2.     if x == 1:
  3.         return False
  4.     for i in range(2,x):
  5.         if x%i == 0:
  6.             return False
  7.     return True
  8.  
  9. def max_value(path):
  10.     with open(path, 'r') as file:
  11.         i = 0
  12.         sum = 0
  13.         maxx = 0
  14.         for line in file:
  15.             for idx, word in enumerate(line.split()):
  16.               number = int(word)
  17.               if idx in (i-1, i, i+1) and not prime(number):
  18.                 if maxx < number:
  19.                     maxx = number
  20.             i = line.split().index(str(maxx))
  21.             sum += maxx
  22.             maxx = 0
  23.         return sum
  24.  
  25.  
  26. print(max_value("text.txt"))
  27.  
  28.