diff options
| author | Андрей Гущин <saintruler@gmail.com> | 2019-03-15 19:33:13 +0300 |
|---|---|---|
| committer | Андрей Гущин <saintruler@gmail.com> | 2019-03-15 19:33:13 +0300 |
| commit | f831ea2581b0ecfee1545323b3bc62a71abf57c6 (patch) | |
| tree | d1b5599abb4e048b5f98b1de17ae2eb643c9a26c | |
| parent | 92b7d6c7b75aa4a6d6a2edc12f76cb45a4d06528 (diff) | |
| parent | 963fab279d069a57ba14e8d77677840272e8c071 (diff) | |
Merge branch 'day1_task1' into 'master'
Day 1 Task 1
See merge request saintruler/trainee!5
| -rw-r--r-- | .gitignore | 2 | ||||
| -rw-r--r-- | day1/task1/task1.py | 37 | ||||
| -rw-r--r-- | day1/task1/task1_data.txt | 1 |
3 files changed, 39 insertions, 1 deletions
@@ -1,2 +1,2 @@ .idea/ -venv/
\ No newline at end of file +venv/ 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 |