diff options
Diffstat (limited to 'day1')
| -rw-r--r-- | day1/task1/task1.py | 37 | ||||
| -rw-r--r-- | day1/task1/task1_data.txt | 1 |
2 files changed, 38 insertions, 0 deletions
diff --git a/day1/task1/task1.py b/day1/task1/task1.py new file mode 100644 index 0000000..a763a97 --- /dev/null +++ b/day1/task1/task1.py @@ -0,0 +1,37 @@ +import os + +CHUNK_SIZE = 1024 + +character = input('Введите один символ: ') +while len(character) != 1: + character = input('Введите РОВНО один символ: ') + + +path = os.path.join(os.getcwd(), 'task1_data.txt') + + +try: + f = open(path) + +except FileNotFoundError as e: + exception_path = str(e).strip('[Errno 2] No such file or directory:')[1:-1] + print(f'"{exception_path}" не существует') + +except PermissionError as e: + exception_path = str(e).strip('[Errno 13] Permission denied:')[1:-1] + print(f'Файл "{exception_path}" не доступен для чтения/записи') + +except IsADirectoryError as e: + exception_path = str(e).strip('[Errno 21] Is a directory:')[1:-1] + print(f'"{exception_path}" является директорией') + +else: + data = f.read(CHUNK_SIZE) + i = data.count(character) + while data: + data = f.read(CHUNK_SIZE) + i += data.count(character) + + f.close() + + print(f'В данном файле {i} символов "{character}"') diff --git a/day1/task1/task1_data.txt b/day1/task1/task1_data.txt new file mode 100644 index 0000000..09dcdd3 --- /dev/null +++ b/day1/task1/task1_data.txt @@ -0,0 +1 @@ +jskdabfkjhaFVADSKNCA coiojAFHAIDjjakhbv;oAKJVBHLSA.C ASBJ BAJ VBASDJ |