From 75ab10b872bf65962e66bb0c4066e186375ba029 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=94=D0=BC=D0=B8=D1=82=D1=80=D0=B8=D0=B9?= Date: Thu, 6 Mar 2025 19:53:57 +0300 Subject: [PATCH] =?UTF-8?q?=D0=94=D0=BE=D0=B1=D0=B0=D0=B2=D0=BB=D0=B5?= =?UTF-8?q?=D0=BD=D1=8B=20=D1=84=D0=B0=D0=B9=D0=BB=D1=8B=20data.txt,=20mai?= =?UTF-8?q?n.py?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .gitignore | 1 + .vscode/launch.json | 7 +++++++ data.txt | 4 ++++ main.py | 43 +++++++++++++++++++++++++++++++++++++++++++ Задание.txt | 1 + 5 files changed, 56 insertions(+) create mode 100644 .gitignore create mode 100644 .vscode/launch.json create mode 100644 data.txt create mode 100644 main.py create mode 100644 Задание.txt diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..8cdcbba --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +output.txt \ No newline at end of file diff --git a/.vscode/launch.json b/.vscode/launch.json new file mode 100644 index 0000000..5c7247b --- /dev/null +++ b/.vscode/launch.json @@ -0,0 +1,7 @@ +{ + // Use IntelliSense to learn about possible attributes. + // Hover to view descriptions of existing attributes. + // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 + "version": "0.2.0", + "configurations": [] +} \ No newline at end of file diff --git a/data.txt b/data.txt new file mode 100644 index 0000000..18133d8 --- /dev/null +++ b/data.txt @@ -0,0 +1,4 @@ +Жили у бабуси 3.5 веселых гуся: один серый другой белый следующий синий поеследний оранж. + +Дед да бабка репу чесали какое заадние придумать да не придумали и решили они посчитать сколько определенных символов в этом тексте да считать не умели, +зато умели писать кодик на питончике ,он им и посчитал сколько и чего тут содержится. \ No newline at end of file diff --git a/main.py b/main.py new file mode 100644 index 0000000..5e4de65 --- /dev/null +++ b/main.py @@ -0,0 +1,43 @@ +import os + +def count_character_and_spaces(file_path, output_path, char_to_count): + try: + if not os.path.exists(file_path): + print("Ошибка: Файл data.txt не найден. Проверьте путь.") + return + + with open(file_path, 'r', encoding='utf-8') as file: + content = file.read() + + char_count = content.count(char_to_count) + space_count = content.count(' ') + dot_count = content.count('.') + comma_count = content.count(',') + + result = (f"Символ '{char_to_count}' встречается {char_count} раз(а).\n" + f"Количество пробелов: {space_count}\n" + f"Количество точек: {dot_count}\n" + f"Количество запятых: {comma_count}\n") + + with open(output_path, 'w', encoding='utf-8') as output_file: + output_file.write(result) + + print("Результат записан в output.txt") + except Exception as e: + print(f"Произошла ошибка: {e}") + + +def main(): + file_path = os.path.join(os.environ['USERPROFILE'], 'Desktop', 'рактика2', 'data.txt') + output_path = os.path.join(os.environ['USERPROFILE'], 'Desktop', 'рактика2', 'output.txt') + + char_to_count = input("Введите символ для поиска: ") + if len(char_to_count) != 1: + print("Ошибка: Нужно ввести ровно один символ.") + return + + count_character_and_spaces(file_path, output_path, char_to_count) + + +if __name__ == "__main__": + main() diff --git a/Задание.txt b/Задание.txt new file mode 100644 index 0000000..ebc6611 --- /dev/null +++ b/Задание.txt @@ -0,0 +1 @@ +Считает кол-во заданного символа и записывает результаты в файл , счиатет запятые и точки ,пробелы. \ No newline at end of file