|
|
|
|
@ -74,20 +74,38 @@ def func_2 (file):
|
|
|
|
|
2. Модуль MOD2.py
|
|
|
|
|
```py
|
|
|
|
|
import os
|
|
|
|
|
while True:
|
|
|
|
|
import MOD1
|
|
|
|
|
|
|
|
|
|
def process_file():
|
|
|
|
|
while True:
|
|
|
|
|
file = input("Введите имя файла: ")
|
|
|
|
|
if os.path.exists(file):
|
|
|
|
|
break
|
|
|
|
|
print("Такого файла нет!")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
KK = float(input("Пороговое значение KK: "))
|
|
|
|
|
MOD1.func_1(file, KK)
|
|
|
|
|
file_1 = file.replace('.txt', '1.txt') # Файл с числами > KK
|
|
|
|
|
file_2 = file.replace('.txt', '2.txt') # Файл с числами ≤ KK
|
|
|
|
|
print("\nИсходный файл:")
|
|
|
|
|
|
|
|
|
|
file_1 = file.replace('.txt', '1.txt')
|
|
|
|
|
file_2 = file.replace('.txt', '2.txt')
|
|
|
|
|
|
|
|
|
|
stats = []
|
|
|
|
|
|
|
|
|
|
read_1 = MOD1.func_2(file)
|
|
|
|
|
if read_1:
|
|
|
|
|
stats.append(('Исходный', read_1))
|
|
|
|
|
|
|
|
|
|
if os.path.exists(file_1):
|
|
|
|
|
read_2 = MOD1.func_2(file_1)
|
|
|
|
|
if read_2:
|
|
|
|
|
stats.append(('> KK', read_2))
|
|
|
|
|
|
|
|
|
|
if os.path.exists(file_2):
|
|
|
|
|
read_3 = MOD1.func_2(file_2)
|
|
|
|
|
if read_3:
|
|
|
|
|
stats.append(('≤ KK', read_3))
|
|
|
|
|
|
|
|
|
|
print("\nИсходный файл:")
|
|
|
|
|
if read_1:
|
|
|
|
|
a, b, c, d, e = read_1
|
|
|
|
|
print(f" Среднее: {a:.2f}")
|
|
|
|
|
@ -98,49 +116,31 @@ else:
|
|
|
|
|
print(" Не удалось рассчитать статистику")
|
|
|
|
|
|
|
|
|
|
print("\nФайл с числами > KK:")
|
|
|
|
|
if os.path.exists(file_1):
|
|
|
|
|
read_2 = MOD1.func_2(file_1)
|
|
|
|
|
if read_2:
|
|
|
|
|
a, b, c, d, e = read_2
|
|
|
|
|
print(f" Среднее: {a:.2f}")
|
|
|
|
|
print(f" Медиана: {b:.2f}")
|
|
|
|
|
print(f" От {c:.2f} до {d:.2f}")
|
|
|
|
|
print(f" Отклонение: {e:.2f}")
|
|
|
|
|
a, b, c, d, e = read_2
|
|
|
|
|
print(f" Среднее: {a:.2f}")
|
|
|
|
|
print(f" Медиана: {b:.2f}")
|
|
|
|
|
print(f" От {c:.2f} до {d:.2f}")
|
|
|
|
|
print(f" Отклонение: {e:.2f}")
|
|
|
|
|
|
|
|
|
|
print("\nФайл с числами ≤ KK:")
|
|
|
|
|
if os.path.exists(file_2):
|
|
|
|
|
read_3 = MOD1.func_2(file_2)
|
|
|
|
|
if read_3:
|
|
|
|
|
a, b, c, d, e = read_3
|
|
|
|
|
print(f" Среднее: {a:.2f}")
|
|
|
|
|
print(f" Медиана: {b:.2f}")
|
|
|
|
|
print(f" От {c:.2f} до {d:.2f}")
|
|
|
|
|
print(f" Отклонение: {e:.2f}")
|
|
|
|
|
|
|
|
|
|
return file, stats
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
3. Модуль MOD0.py
|
|
|
|
|
```py
|
|
|
|
|
import MOD2
|
|
|
|
|
import pickle
|
|
|
|
|
import MOD1
|
|
|
|
|
|
|
|
|
|
fname = input("Исходный файл из MOD2: ")
|
|
|
|
|
fname1 = fname.replace('.txt', '1.txt')
|
|
|
|
|
fname2 = fname.replace('.txt', '2.txt')
|
|
|
|
|
|
|
|
|
|
stats_all = []
|
|
|
|
|
stats1 = MOD1.func_2(fname)
|
|
|
|
|
if stats1:
|
|
|
|
|
stats_all.append(('Исходный', stats1))
|
|
|
|
|
|
|
|
|
|
stats2 = MOD1.func_2(fname1) if stats1 else None
|
|
|
|
|
if stats2:
|
|
|
|
|
stats_all.append(('> KK', stats2))
|
|
|
|
|
import MOD2
|
|
|
|
|
|
|
|
|
|
stats3 = MOD1.func_2(fname2) if stats1 else None
|
|
|
|
|
if stats3:
|
|
|
|
|
stats_all.append(('≤ KK', stats3))
|
|
|
|
|
fname, stats_all = MOD2.process_file()
|
|
|
|
|
|
|
|
|
|
with open("RES2a.bin", 'wb') as f:
|
|
|
|
|
pickle.dump(stats_all, f)
|
|
|
|
|
|