diff --git a/__pycache__/function.cpython-311.pyc b/__pycache__/function.cpython-311.pyc new file mode 100644 index 0000000..2d41cdd Binary files /dev/null and b/__pycache__/function.cpython-311.pyc differ diff --git a/function.py b/function.py index 5ed5236..b28cbbd 100644 --- a/function.py +++ b/function.py @@ -8,26 +8,29 @@ init(autoreset=True) # --------------------------заполнение-и-вывод-списка------------------------------------ + def rand(): range1 = int(input(Fore.GREEN + "Введите длинну списка: " + Fore.RESET)) range2 = int(input(Fore.GREEN + "Введите предел чисел: " + Fore.RESET)) - massive = random.sample(range(0, range2), range1) - return massive + return random.sample(range(0, range2), range1) + def print_table(masive, num_cols): massive = masive num_rows = len(massive) // num_cols + (len(massive) % num_cols > 0) for i in range(num_rows): - row = massive[i*num_cols:(i+1)*num_cols] - row += [''] * (num_cols - len(row)) # добавляем пустые элементы до num_cols - print((Fore.BLUE + '{:<7}' * num_cols).format(*row)) + row = massive[i * num_cols : (i + 1) * num_cols] + row += [""] * (num_cols - len(row)) # добавляем пустые элементы до num_cols + print((Fore.BLUE + "{:<7}" * num_cols).format(*row)) + # -----------------------------вывод-графиков------------------------------------------ -def real_graph(masive): #вещественный график=-=--=-=-=-=-=-= + +def real_graph(masive): # вещественный график=-=--=-=-=-=-=-= massive = masive max_height = max(massive) - length = len(massive) + length = len(massive) for i in range(max_height, 0, -1): for q in range(0, length): if massive[q] >= i: @@ -35,83 +38,108 @@ def real_graph(masive): #вещественный график=-=--=-=-=-=-=-= else: print(Fore.RED + " ", end="") - print(' ', Fore.BLUE + str(i)) + print(" ", Fore.BLUE + str(i)) -def percentage_graph(masive, max_or_mean): #процентный график=-=--=-=-=-=-=-= + +def percentage_graph(masive, max_or_mean): # процентный график=-=--=-=-=-=-=-= massive = masive # нахождение высоты - max_height = max(massive) / 20 # делит таблицу на 20 частей по 5% + max_height = max(massive) / 20 # делит таблицу на 20 частей по 5% # нахождение длинны - chunks = np.array_split(massive, 20)# Разбиваем массив на 20 частей - max_values = np.zeros(20)# Инициализируем массивы для хранения максимальных значений и их индексов + chunks = np.array_split(massive, 20) # Разбиваем массив на 20 частей + max_values = np.zeros( + 20 + ) # Инициализируем массивы для хранения максимальных значений и их индексов max_indices = np.zeros(20) if max_or_mean == "arf": - means = [int(np.nanmean(chunk)) for chunk in chunks]# вычисляем среднее арифметическое каждого подсписка + means = [ + int(np.nanmean(chunk)) for chunk in chunks + ] # вычисляем среднее арифметическое каждого подсписка elif max_or_mean == "max": - for i, chunk in enumerate(chunks): # Находим максимальное значение и его индекс в каждой части + for i, chunk in enumerate( + chunks + ): # Находим максимальное значение и его индекс в каждой части if len(chunk) > 0: max_index = np.argmax(chunk) - max_indices[i] = i*len(chunk) + max_index + max_indices[i] = i * len(chunk) + max_index else: print(Fore.RED + "Приятель, делай выбор!") return # строим график for i in range(21, 0, -1): - index_height = int((max_height * i) - max_height) # создаёт индекс для сравнения высот + index_height = int( + (max_height * i) - max_height + ) # создаёт индекс для сравнения высот for q in range(0, 20): if max_or_mean == "arf": value = means[q] elif max_or_mean == "max": - index_lenght = max_indices[q] # создаёт индекс длинны для сравненияс высотой + index_lenght = max_indices[ + q + ] # создаёт индекс длинны для сравненияс высотой value = massive[int(index_lenght)] if len(massive) > 0 and value >= index_height: print(Fore.RED + "[]", end="") else: print(Fore.RED + " ", end="") - print(' ', Fore.BLUE + str((i-1)*5), Fore.BLUE + '%') + print(" ", Fore.BLUE + str((i - 1) * 5), Fore.BLUE + "%") + # -----------------------------назначение-настроек---------------------------------------------- -def graf(show_graph): # параметр базового вывода графика + +def graf(show_graph): # параметр базового вывода графика while True: if show_graph is not None: print(Fore.GREEN + "Выводится ли график - ", Fore.BLUE + str(show_graph)) else: print(Fore.GREEN + "Выводится ли график - ", Fore.BLUE + "None") show_graph = input(Fore.GREEN + "Строить график? - yes или no\n" + Fore.RESET) - if show_graph in ['yes', 'no']: + if show_graph in ["yes", "no"]: break os.system("cls") print(Fore.RED + "Приятель, делай выбор!") return show_graph -def type_graf(show_graph, max_or_mean): # параметр типа графика - if show_graph == 'yes': + +def type_graf(show_graph, max_or_mean): # параметр типа графика + if show_graph == "yes": while True: if max_or_mean is not None: print(Fore.GREEN + "Тип графика - ", Fore.BLUE + str(max_or_mean)) else: print(Fore.GREEN + "Тип графика - ", Fore.BLUE + "None") - max_or_mean = input(Fore.GREEN + "Строить график по арифметической сумме(arf)\nили высшим точкам(max)?\n" + Fore.RESET) - if max_or_mean in ['arf', 'max']: + max_or_mean = input( + Fore.GREEN + + "Строить график по арифметической сумме(arf)\nили высшим точкам(max)?\n" + + Fore.RESET + ) + if max_or_mean in ["arf", "max"]: break os.system("cls") print(Fore.RED + "Приятель, делай выбор!") - elif show_graph == 'no': - max_or_mean = 'arf' + elif show_graph == "no": + max_or_mean = "arf" return max_or_mean -def num_column(num_cols): # параметр кол-ва столбцов таблице - while True: + +def num_column(num_cols): # параметр кол-ва столбцов таблице + while True: try: if num_cols is not None: print(Fore.GREEN + "кол-во колнок - ", Fore.BLUE + str(num_cols)) else: print(Fore.GREEN + "кол-во колнок - ", Fore.BLUE + "None") - num_cols = int(input(Fore.GREEN + "Укажите кол-во колнок в таблиц\n(не больше 10) - \n" + Fore.RESET)) + num_cols = int( + input( + Fore.GREEN + + "Укажите кол-во колнок в таблиц\n(не больше 10) - \n" + + Fore.RESET + ) + ) except ValueError: os.system("cls") print(Fore.RED + "Приятель, числа надо вводить, ЧИСЛА!\nЗаново!") @@ -122,17 +150,19 @@ def num_column(num_cols): # параметр кол-ва столбцов таб print(Fore.RED + "Приятель, не больше 10!") return num_cols + # -----------------------------menu-------------------------------------------------- + def menu(show_graph, max_or_mean, num_cols): while True: os.system("cls") menu = input( - Fore.GREEN + - "\nДля продолжения нажмите Enter.\nЕсли хотите изменить настройки введите change\nпосмотреть настройки - set\nЕсли хотите завершить работу введите end.\n\n " - + Fore.RED - ) - + Fore.GREEN + + "\nДля продолжения нажмите Enter.\nЕсли хотите изменить настройки введите change\nпосмотреть настройки - set\nЕсли хотите завершить работу введите end.\n\n " + + Fore.RED + ) + match menu: case "": os.system("cls") @@ -141,18 +171,21 @@ def menu(show_graph, max_or_mean, num_cols): case "set": setings(show_graph, max_or_mean, num_cols) case "change": - show_graph, max_or_mean, num_cols = changes(show_graph, max_or_mean, num_cols) + show_graph, max_or_mean, num_cols = changes( + show_graph, max_or_mean, num_cols + ) case "end": os.system("cls") print( - Fore.GREEN + - "Спасибо за то, что воспользовались услугами\nкомпании ООО'Random'.\nС вас много деняг." + Fore.GREEN + + "Спасибо за то, что воспользовались услугами\nкомпании ООО'Random'.\nС вас много деняг." ) breaker = False return breaker, show_graph, max_or_mean, num_cols case other: pass + def setings(show_graph, max_or_mean, num_cols): while True: os.system("cls") @@ -162,12 +195,13 @@ def setings(show_graph, max_or_mean, num_cols): menu = input(Fore.GREEN + "\nДля возвращения нажмите Enter. ") break + def changes(show_graph, max_or_mean, num_cols): while True: os.system("cls") change = input( - Fore.GREEN + - "Если хотите выводить/не выводить график\nвведите graf\nЕсли хотите изменить тип графика\nвведите type\nЕсли хотите изменить кол-во столбцов\nвведите col\nЕсли хотите вернуться к работе то\nвведите cont\n" + Fore.GREEN + + "Если хотите выводить/не выводить график\nвведите graf\nЕсли хотите изменить тип графика\nвведите type\nЕсли хотите изменить кол-во столбцов\nвведите col\nЕсли хотите вернуться к работе то\nвведите cont\n" + Fore.RED ) match change: @@ -179,4 +213,3 @@ def changes(show_graph, max_or_mean, num_cols): num_cols = num_column(num_cols) case "cont": return show_graph, max_or_mean, num_cols - diff --git a/rand.py b/rand.py index 941fcc9..fae053c 100644 --- a/rand.py +++ b/rand.py @@ -6,26 +6,26 @@ init(autoreset=True) os.system("cls") -masive = [] # инициализация основного масива +masive = [] # инициализация основного масива -show_graph = None # параметр базового вывода графика +show_graph = None # параметр базового вывода графика show_graph = function.graf(show_graph) -max_or_mean = None # параметр типа графика +max_or_mean = None # параметр типа графика max_or_mean = function.type_graf(show_graph, max_or_mean) -num_cols = None # параметр кол-ва столбцов таблице +num_cols = None # параметр кол-ва столбцов таблице num_cols = function.num_column(num_cols) while True: - try: - masive = function.rand() # заполнение массива случайными числами + try: + masive = function.rand() # заполнение массива случайными числами match show_graph: case "yes": function.print_table(masive, num_cols) max_height = max(masive) length = len(masive) - if max_height > 20 or length > 20: + if max_height > 20 or length > 20: function.percentage_graph(masive, max_or_mean) else: function.real_graph(masive) @@ -39,10 +39,12 @@ while True: os.system("cls") print(Fore.RED + "Приятель, внимательнее! \nЗаново!") continue - - breaker, show_graph, max_or_mean, num_cols = function.menu(show_graph, max_or_mean, num_cols) - + + breaker, show_graph, max_or_mean, num_cols = function.menu( + show_graph, max_or_mean, num_cols + ) + if breaker == False: break -# ВСЁ ГОТОВО) \ No newline at end of file +# ВСЁ ГОТОВО)