commit 75ab10b872bf65962e66bb0c4066e186375ba029 Author: Дмитрий Date: Thu Mar 6 19:53:57 2025 +0300 Добавлены файлы data.txt, main.py 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