From fe915f67c308aed885a6fc74550d2a4f6861e077 Mon Sep 17 00:00:00 2001 From: Wojtek Date: Fri, 19 Jan 2024 20:41:55 +0100 Subject: [PATCH] zadania E --- TaskE01/run.py | 14 ++++++++++++++ TaskE02/run.py | 14 ++++++++++++++ TaskE03/run.py | 14 ++++++++++++++ TaskE04/run.py | 14 ++++++++++++++ TaskE05/run.py | 14 ++++++++++++++ TaskE06/run.py | 14 ++++++++++++++ TaskE07/run.py | 14 ++++++++++++++ TaskE08/run.py | 14 ++++++++++++++ TaskE09/run.py | 14 ++++++++++++++ TaskE10/run.py | 14 ++++++++++++++ TaskE16/run.py | 18 ++++++++++++++++++ TaskE43/run.py | 20 ++++++++++++++++++++ TaskE48/run.py | 16 ++++++++++++++++ 13 files changed, 194 insertions(+) create mode 100644 TaskE01/run.py create mode 100644 TaskE02/run.py create mode 100644 TaskE03/run.py create mode 100644 TaskE04/run.py create mode 100644 TaskE05/run.py create mode 100644 TaskE06/run.py create mode 100644 TaskE07/run.py create mode 100644 TaskE08/run.py create mode 100644 TaskE09/run.py create mode 100644 TaskE10/run.py create mode 100644 TaskE16/run.py create mode 100644 TaskE43/run.py create mode 100644 TaskE48/run.py diff --git a/TaskE01/run.py b/TaskE01/run.py new file mode 100644 index 0000000..09d7b38 --- /dev/null +++ b/TaskE01/run.py @@ -0,0 +1,14 @@ +import re + + +def check_number(file_path): + with open(file_path, 'r', encoding='utf-8') as file: + pattern = r'^(25|50|75|100|[1-9]\d*(25|50|75|00))$' + for line in file: + if re.match(pattern, line.strip()): + print('yes') + else: + print('no') + +file_path = 'TaskE01/test.in' +check_number(file_path) diff --git a/TaskE02/run.py b/TaskE02/run.py new file mode 100644 index 0000000..e88031b --- /dev/null +++ b/TaskE02/run.py @@ -0,0 +1,14 @@ +import re + +def extract_digits(file_path): + pattern = r'^(\d{2})-\d{3}$' + with open(file_path, 'r', encoding='utf-8') as file: + for line in file: + match = re.match(pattern, line.strip()) + if match: + print(match.group(1)) + else: + print("") + +file_path = 'TaskE02/test.in' +extract_digits(file_path) \ No newline at end of file diff --git a/TaskE03/run.py b/TaskE03/run.py new file mode 100644 index 0000000..e814b31 --- /dev/null +++ b/TaskE03/run.py @@ -0,0 +1,14 @@ +import re + +def nip(file_path): + pattern = r'^\d{3}-\d{3}-\d{2}-\d{2}$|^\d{3}-\d{2}-\d{2}-\d{3}$' + with open(file_path, 'r', encoding='utf-8') as file: + for line in file: + if re.match(pattern, line.strip()): + print('yes') + else: + print('no') + + +file_path = 'TaskE03/test.in' +nip(file_path) \ No newline at end of file diff --git a/TaskE04/run.py b/TaskE04/run.py new file mode 100644 index 0000000..7d44ea1 --- /dev/null +++ b/TaskE04/run.py @@ -0,0 +1,14 @@ +import re + +def check_phone(file_path): + pattern = r'^555(-\d{3}-\d{3}$|\s\d{3}\s\d{3}$)' + + with open(file_path, 'r', encoding='utf-8') as file: + for line in file: + if re.match(pattern, line.strip()): + print('yes') + else: + print('no') + +file_path = 'TaskE04/test.in' +check_phone(file_path) \ No newline at end of file diff --git a/TaskE05/run.py b/TaskE05/run.py new file mode 100644 index 0000000..5f0ef22 --- /dev/null +++ b/TaskE05/run.py @@ -0,0 +1,14 @@ +import re + +def akronim(file_path): + pattern = r'^(PCMCIA|WYSIWYG|[A-Z]{2,5})$' + + with open(file_path, 'r', encoding='utf-8') as file: + for line in file: + if re.match(pattern, line.strip()): + print('yes') + else: + print('no') + +file_path = 'TaskE05/test.in' +akronim(file_path) \ No newline at end of file diff --git a/TaskE06/run.py b/TaskE06/run.py new file mode 100644 index 0000000..ba27452 --- /dev/null +++ b/TaskE06/run.py @@ -0,0 +1,14 @@ +import re + +def digits(file_path): + pattern = r'^[1-9]\d{4,5}$' + + with open(file_path, 'r', encoding='utf-8') as file: + for line in file: + if re.match(pattern, line.strip()): + print('yes') + else: + print('no') + +file_path = 'TaskE06/test.in' +digits(file_path) \ No newline at end of file diff --git a/TaskE07/run.py b/TaskE07/run.py new file mode 100644 index 0000000..fb20340 --- /dev/null +++ b/TaskE07/run.py @@ -0,0 +1,14 @@ +import re + +def stars(file_path): + pattern = r'^\*+$' + + with open(file_path, 'r', encoding='utf-8') as file: + for line in file: + if re.match(pattern, line.strip()): + print('yes') + else: + print('no') + +file_path = 'TaskE07/test.in' +stars(file_path) \ No newline at end of file diff --git a/TaskE08/run.py b/TaskE08/run.py new file mode 100644 index 0000000..4b0e099 --- /dev/null +++ b/TaskE08/run.py @@ -0,0 +1,14 @@ +import re + +def hihi(file_path): + pattern = r'^(hi){2,}!*$' + + with open(file_path, 'r', encoding='utf-8') as file: + for line in file: + if re.match(pattern, line.strip()): + print('yes') + else: + print('no') + +file_path = 'TaskE08/test.in' +hihi(file_path) \ No newline at end of file diff --git a/TaskE09/run.py b/TaskE09/run.py new file mode 100644 index 0000000..73ceb3f --- /dev/null +++ b/TaskE09/run.py @@ -0,0 +1,14 @@ +import re + +def big_letter(file_path): + pattern = r'.*[A-Z]\d{2}.*' + + with open(file_path, 'r', encoding='utf-8') as file: + for line in file: + if re.match(pattern, line.strip()): + print('yes') + else: + print('no') + +file_path = 'TaskE09/test.in' +big_letter(file_path) \ No newline at end of file diff --git a/TaskE10/run.py b/TaskE10/run.py new file mode 100644 index 0000000..53dfc72 --- /dev/null +++ b/TaskE10/run.py @@ -0,0 +1,14 @@ +import re + +def big_letter(file_path): + pattern = r'^[1-9A-F]0*$' + + with open(file_path, 'r', encoding='utf-8') as file: + for line in file: + if re.match(pattern, line.strip()): + print('yes') + else: + print('no') + +file_path = 'TaskE10/test.in' +big_letter(file_path) \ No newline at end of file diff --git a/TaskE16/run.py b/TaskE16/run.py new file mode 100644 index 0000000..cebe2c6 --- /dev/null +++ b/TaskE16/run.py @@ -0,0 +1,18 @@ +import re + +def check_equation(file_path): + pattern = r'^\s*(x|[1-9]\d*)\s*[\+\-\*\/]\s*(x|[1-9]\d*)\s*=\s*(x|[1-9]\d*)\s*$' + + with open(file_path, 'r', encoding='utf-8') as file: + for line in file: + line = line.strip() + if re.match(pattern, line): + if line.count('x') == 1: + print('yes') + else: + print('no') + else: + print('no') + +file_path = 'TaskE16/test.in' +check_equation(file_path) \ No newline at end of file diff --git a/TaskE43/run.py b/TaskE43/run.py new file mode 100644 index 0000000..9d830b1 --- /dev/null +++ b/TaskE43/run.py @@ -0,0 +1,20 @@ +import re + +def pattern(file_path): + pattern = r'^[a-zA-ZąćęłńóśżźĄĆĘŁŃÓŚŻŹ]+(!+|1|one|eleven)+$' + one_eleven_pattern = r'(1|one|eleven)' + + with open(file_path, 'r', encoding='utf-8') as file: + for line in file: + line = line.strip() + if re.match(pattern, line): + if line.count('!') >= 2 and re.search(one_eleven_pattern, line): + print('yes') + else: + print('no') + else: + print('no') + + +file_path = 'TaskE43/test.in' +pattern(file_path) \ No newline at end of file diff --git a/TaskE48/run.py b/TaskE48/run.py new file mode 100644 index 0000000..b269f85 --- /dev/null +++ b/TaskE48/run.py @@ -0,0 +1,16 @@ +import re + +def pattern(file_path): + pattern = r'^(([a-ząćęłńóśżź][A-ZĄĆĘŁŃÓŚŻŹ])+|([A-ZĄĆĘŁŃÓŚŻŹ][a-ząćęłńóśżź])+)' + + with open(file_path, 'r', encoding='utf-8') as file: + for line in file: + line = line.strip() + if re.match(pattern, line) and len(line) >= 2: + print('yes') + else: + print('no') + + +file_path = 'TaskE48/test.in' +pattern(file_path) \ No newline at end of file