ответвлено от main/python-labs
Tema9/test.md
Этот коммит содержится в:
@@ -1,23 +1,7 @@
|
||||
import MOD2
|
||||
import pickle
|
||||
import MOD1
|
||||
import MOD2
|
||||
|
||||
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))
|
||||
|
||||
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)
|
||||
|
||||
@@ -1,45 +1,62 @@
|
||||
import os
|
||||
import MOD1
|
||||
|
||||
while True:
|
||||
file = input("Введите имя файла: ")
|
||||
if os.path.exists(file):
|
||||
break
|
||||
print("Такого файла нет!")
|
||||
def process_file():
|
||||
while True:
|
||||
file = input("Введите имя файла: ")
|
||||
if os.path.exists(file):
|
||||
break
|
||||
print("Такого файла нет!")
|
||||
|
||||
KK = float(input("Пороговое значение KK: "))
|
||||
MOD1.func_1(file, KK)
|
||||
KK = float(input("Пороговое значение KK: "))
|
||||
MOD1.func_1(file, KK)
|
||||
|
||||
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}")
|
||||
print(f" Медиана: {b:.2f}")
|
||||
print(f" От {c:.2f} до {d:.2f}")
|
||||
print(f" Отклонение: {e:.2f}")
|
||||
else:
|
||||
print(" Не удалось рассчитать статистику")
|
||||
|
||||
file_1 = file.replace('.txt', '1.txt')
|
||||
file_2 = file.replace('.txt', '2.txt')
|
||||
|
||||
print("\nИсходный файл:")
|
||||
read_1 = MOD1.func_2(file)
|
||||
if read_1:
|
||||
a, b, c, d, e = read_1
|
||||
print(f" Среднее: {a:.2f}")
|
||||
print(f" Медиана: {b:.2f}")
|
||||
print(f" От {c:.2f} до {d:.2f}")
|
||||
print(f" Отклонение: {e:.2f}")
|
||||
else:
|
||||
print(" Не удалось рассчитать статистику")
|
||||
|
||||
print("\nФайл с числами > KK:")
|
||||
if os.path.exists(file_1):
|
||||
read_2 = MOD1.func_2(file_1)
|
||||
print("\nФайл с числами > KK:")
|
||||
if read_2:
|
||||
a, b, c, d, e = 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}")
|
||||
|
||||
print("\nФайл с числами ≤ KK:")
|
||||
if os.path.exists(file_2):
|
||||
read_3 = MOD1.func_2(file_2)
|
||||
print("\nФайл с числами ≤ KK:")
|
||||
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
|
||||
|
||||
if __name__ == "__main__":
|
||||
process_file()
|
||||
|
||||
112
TEMA9/test.md
112
TEMA9/test.md
@@ -74,73 +74,73 @@ def func_2 (file):
|
||||
2. Модуль MOD2.py
|
||||
```py
|
||||
import os
|
||||
while True:
|
||||
import MOD1
|
||||
|
||||
file = input("Введите имя файла: ")
|
||||
if os.path.exists(file):
|
||||
break
|
||||
print("Такого файла нет!")
|
||||
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')
|
||||
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}")
|
||||
print(f" Медиана: {b:.2f}")
|
||||
print(f" От {c:.2f} до {d:.2f}")
|
||||
print(f" Отклонение: {e:.2f}")
|
||||
else:
|
||||
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Исходный файл:")
|
||||
read_1 = MOD1.func_2(file)
|
||||
if read_1:
|
||||
a, b, c, d, e = read_1
|
||||
print(f" Среднее: {a:.2f}")
|
||||
print(f" Медиана: {b:.2f}")
|
||||
print(f" От {c:.2f} до {d:.2f}")
|
||||
print(f" Отклонение: {e:.2f}")
|
||||
else:
|
||||
print(" Не удалось рассчитать статистику")
|
||||
print("\nФайл с числами > KK:")
|
||||
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}")
|
||||
|
||||
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}")
|
||||
|
||||
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}")
|
||||
print("\nФайл с числами ≤ KK:")
|
||||
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
|
||||
import MOD2
|
||||
|
||||
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))
|
||||
|
||||
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)
|
||||
|
||||
Ссылка в новой задаче
Block a user