уберите строку
file.readline()
и в принте будут все элементы что в файле, с
file.readline()
вы теряете первый элемент
Python:
with open(f"{file_name}.txt", "r") as file:
# file.readline()
data = file.readlines()
numbers = [int(x.replace("\n", "")) for x in data]
numbers = sorted(numbers, reverse=True)
print(numbers)
и в for уберите + 1, в принте тоже все элементы
Python:
for i in range(len(numbers)):
print(numbers[i])
...
в итоге так работает без ошибок, я не понял смысла задачи, но ошибок нет
Python:
def get_max_summ(file_name):
delit_7 = [1]
delit_2 = [1]
delit_14 = [1]
with open(f"{file_name}.txt", "r") as file:
data = file.readlines()
numbers = [int(x.replace("\n", "")) for x in data]
numbers = sorted(numbers, reverse=True)
for i in range(len(numbers)):
if numbers[i] % 7 == 0 and numbers[i] % 2 != 0:
if delit_7[0] == 1:
delit_7[0] = numbers[i]
else:
delit_7.append(numbers[i])
if numbers[i] % 2 == 0 and numbers[i] % 7 != 0:
if delit_2[0] == 1:
delit_2[0] = numbers[i]
else:
delit_2.append(numbers[i])
if numbers[i] % 14 == 0 and numbers[i] % 2 != 0:
if delit_14[0] == 1:
delit_14[0] = numbers[i]
else:
delit_14.append(numbers[i])
delit_7 = sorted(delit_7, reverse=True)
delit_2 = sorted(delit_2, reverse=True)
delit_14 = sorted(delit_14, reverse=True)
if delit_7[0] > delit_2[0]:
max_number = [delit_7[0]]
else:
max_number = [delit_2[0]]
if max_number[0] < delit_14[0]:
max_number = [delit_14[0]]
max_1 = max_number[0] * delit_14[0]
max_2 = delit_7[0] * delit_2[0]
if max_1 > max_2:
print(max_1)
else:
print(max_2)
get_max_summ('27985_A')
# get_max_summ('27985_B')