ответвлено от main/python-labs
Tema9/test.md
Этот коммит содержится в:
@@ -1,23 +1,7 @@
|
|||||||
import MOD2
|
|
||||||
import pickle
|
import pickle
|
||||||
import MOD1
|
import MOD2
|
||||||
|
|
||||||
fname = input("Исходный файл из MOD2: ")
|
fname, stats_all = MOD2.process_file()
|
||||||
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))
|
|
||||||
|
|
||||||
stats3 = MOD1.func_2(fname2) if stats1 else None
|
|
||||||
if stats3:
|
|
||||||
stats_all.append(('≤ KK', stats3))
|
|
||||||
|
|
||||||
with open("RES2a.bin", 'wb') as f:
|
with open("RES2a.bin", 'wb') as f:
|
||||||
pickle.dump(stats_all, f)
|
pickle.dump(stats_all, f)
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
import os
|
import os
|
||||||
import MOD1
|
import MOD1
|
||||||
|
|
||||||
|
def process_file():
|
||||||
while True:
|
while True:
|
||||||
file = input("Введите имя файла: ")
|
file = input("Введите имя файла: ")
|
||||||
if os.path.exists(file):
|
if os.path.exists(file):
|
||||||
@@ -13,8 +14,23 @@ MOD1.func_1(file, KK)
|
|||||||
file_1 = file.replace('.txt', '1.txt')
|
file_1 = file.replace('.txt', '1.txt')
|
||||||
file_2 = file.replace('.txt', '2.txt')
|
file_2 = file.replace('.txt', '2.txt')
|
||||||
|
|
||||||
print("\nИсходный файл:")
|
stats = []
|
||||||
|
|
||||||
read_1 = MOD1.func_2(file)
|
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:
|
if read_1:
|
||||||
a, b, c, d, e = read_1
|
a, b, c, d, e = read_1
|
||||||
print(f" Среднее: {a:.2f}")
|
print(f" Среднее: {a:.2f}")
|
||||||
@@ -25,21 +41,22 @@ else:
|
|||||||
print(" Не удалось рассчитать статистику")
|
print(" Не удалось рассчитать статистику")
|
||||||
|
|
||||||
print("\nФайл с числами > KK:")
|
print("\nФайл с числами > KK:")
|
||||||
if os.path.exists(file_1):
|
|
||||||
read_2 = MOD1.func_2(file_1)
|
|
||||||
if read_2:
|
if read_2:
|
||||||
a, b, c, d, e = read_2 # ← ВОТ ЭТА СТРОКА БЫЛА С ОШИБКОЙ!
|
a, b, c, d, e = read_2
|
||||||
print(f" Среднее: {a:.2f}")
|
print(f" Среднее: {a:.2f}")
|
||||||
print(f" Медиана: {b:.2f}")
|
print(f" Медиана: {b:.2f}")
|
||||||
print(f" От {c:.2f} до {d:.2f}")
|
print(f" От {c:.2f} до {d:.2f}")
|
||||||
print(f" Отклонение: {e:.2f}")
|
print(f" Отклонение: {e:.2f}")
|
||||||
|
|
||||||
print("\nФайл с числами ≤ KK:")
|
print("\nФайл с числами ≤ KK:")
|
||||||
if os.path.exists(file_2):
|
|
||||||
read_3 = MOD1.func_2(file_2)
|
|
||||||
if read_3:
|
if read_3:
|
||||||
a, b, c, d, e = read_3
|
a, b, c, d, e = read_3
|
||||||
print(f" Среднее: {a:.2f}")
|
print(f" Среднее: {a:.2f}")
|
||||||
print(f" Медиана: {b:.2f}")
|
print(f" Медиана: {b:.2f}")
|
||||||
print(f" От {c:.2f} до {d:.2f}")
|
print(f" От {c:.2f} до {d:.2f}")
|
||||||
print(f" Отклонение: {e:.2f}")
|
print(f" Отклонение: {e:.2f}")
|
||||||
|
|
||||||
|
return file, stats
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
process_file()
|
||||||
|
|||||||
@@ -74,20 +74,38 @@ def func_2 (file):
|
|||||||
2. Модуль MOD2.py
|
2. Модуль MOD2.py
|
||||||
```py
|
```py
|
||||||
import os
|
import os
|
||||||
while True:
|
import MOD1
|
||||||
|
|
||||||
|
def process_file():
|
||||||
|
while True:
|
||||||
file = input("Введите имя файла: ")
|
file = input("Введите имя файла: ")
|
||||||
if os.path.exists(file):
|
if os.path.exists(file):
|
||||||
break
|
break
|
||||||
print("Такого файла нет!")
|
print("Такого файла нет!")
|
||||||
|
|
||||||
|
|
||||||
KK = float(input("Пороговое значение KK: "))
|
KK = float(input("Пороговое значение KK: "))
|
||||||
MOD1.func_1(file, KK)
|
MOD1.func_1(file, KK)
|
||||||
file_1 = file.replace('.txt', '1.txt') # Файл с числами > KK
|
|
||||||
file_2 = file.replace('.txt', '2.txt') # Файл с числами ≤ KK
|
file_1 = file.replace('.txt', '1.txt')
|
||||||
print("\nИсходный файл:")
|
file_2 = file.replace('.txt', '2.txt')
|
||||||
|
|
||||||
|
stats = []
|
||||||
|
|
||||||
read_1 = MOD1.func_2(file)
|
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:
|
if read_1:
|
||||||
a, b, c, d, e = read_1
|
a, b, c, d, e = read_1
|
||||||
print(f" Среднее: {a:.2f}")
|
print(f" Среднее: {a:.2f}")
|
||||||
@@ -98,49 +116,31 @@ else:
|
|||||||
print(" Не удалось рассчитать статистику")
|
print(" Не удалось рассчитать статистику")
|
||||||
|
|
||||||
print("\nФайл с числами > KK:")
|
print("\nФайл с числами > KK:")
|
||||||
if os.path.exists(file_1):
|
|
||||||
read_2 = MOD1.func_2(file_1)
|
|
||||||
if read_2:
|
if read_2:
|
||||||
a, b, c, d, e = read_2
|
a, b, c, d, e = read_2
|
||||||
print(f" Среднее: {a:.2f}")
|
print(f" Среднее: {a:.2f}")
|
||||||
print(f" Медиана: {b:.2f}")
|
print(f" Медиана: {b:.2f}")
|
||||||
print(f" От {c:.2f} до {d:.2f}")
|
print(f" От {c:.2f} до {d:.2f}")
|
||||||
print(f" Отклонение: {e:.2f}")
|
print(f" Отклонение: {e:.2f}")
|
||||||
|
|
||||||
print("\nФайл с числами ≤ KK:")
|
print("\nФайл с числами ≤ KK:")
|
||||||
if os.path.exists(file_2):
|
|
||||||
read_3 = MOD1.func_2(file_2)
|
|
||||||
if read_3:
|
if read_3:
|
||||||
a, b, c, d, e = read_3
|
a, b, c, d, e = read_3
|
||||||
print(f" Среднее: {a:.2f}")
|
print(f" Среднее: {a:.2f}")
|
||||||
print(f" Медиана: {b:.2f}")
|
print(f" Медиана: {b:.2f}")
|
||||||
print(f" От {c:.2f} до {d:.2f}")
|
print(f" От {c:.2f} до {d:.2f}")
|
||||||
print(f" Отклонение: {e:.2f}")
|
print(f" Отклонение: {e:.2f}")
|
||||||
|
|
||||||
|
return file, stats
|
||||||
```
|
```
|
||||||
|
|
||||||
|
|
||||||
3. Модуль MOD0.py
|
3. Модуль MOD0.py
|
||||||
```py
|
```py
|
||||||
import MOD2
|
|
||||||
import pickle
|
import pickle
|
||||||
import MOD1
|
import MOD2
|
||||||
|
|
||||||
fname = input("Исходный файл из MOD2: ")
|
fname, stats_all = MOD2.process_file()
|
||||||
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))
|
|
||||||
|
|
||||||
stats3 = MOD1.func_2(fname2) if stats1 else None
|
|
||||||
if stats3:
|
|
||||||
stats_all.append(('≤ KK', stats3))
|
|
||||||
|
|
||||||
with open("RES2a.bin", 'wb') as f:
|
with open("RES2a.bin", 'wb') as f:
|
||||||
pickle.dump(stats_all, f)
|
pickle.dump(stats_all, f)
|
||||||
|
|||||||
Ссылка в новой задаче
Block a user