форкнуто от main/python-labs
Родитель
78dbc5f4ff
Сommit
52f2c3d8b2
@ -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)
|
||||
|
||||
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(" Не удалось рассчитать статистику")
|
||||
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(" Не удалось рассчитать статистику")
|
||||
|
||||
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()
|
||||
|
||||
Загрузка…
Ссылка в новой задаче