diff --git a/TaskE04/run.py b/TaskE04/run.py new file mode 100644 index 0000000..4cdc41c --- /dev/null +++ b/TaskE04/run.py @@ -0,0 +1,13 @@ +import re + +def analyze_line(line): + phone_pattern = re.compile(r'^555-\d{3}-\d{3}$|^555\s\d{3}\s\d{3}$') + + if phone_pattern.match(line): + print('yes') + else: + print('no') + +with open('test.in', 'r') as file: + for line in file: + analyze_line(line.rstrip()) \ No newline at end of file diff --git a/TaskE04/test.in b/TaskE04/test.in index 73010fc..b83bfef 100644 --- a/TaskE04/test.in +++ b/TaskE04/test.in @@ -10,3 +10,5 @@ 556 345 667 556 345 6675 556 345-667 +555 555 555 +555 555 555 \ No newline at end of file diff --git a/TaskE11/run.py b/TaskE11/run.py new file mode 100644 index 0000000..6ffbe7c --- /dev/null +++ b/TaskE11/run.py @@ -0,0 +1,28 @@ +import re + +def check_divisibility(line): + # Sprawdzanie, czy napis jest zapisany dziesiętnie i czy jest podzielny przez 4 + decimal_pattern = re.compile(r'^0$|^[1-9][0-9]*$') + if decimal_pattern.match(line) and int(line) % 4 == 0: + return 'yes' + + # Sprawdzanie, czy napis jest zapisany szesnastkowo i czy jest podzielny przez 4 + hex_pattern = re.compile(r'^0x[1-9A-F]+$|^0x0$') + if hex_pattern.match(line) and int(line, 16) % 4 == 0: + return 'yes' + + return 'no' + +def main(file_path): + try: + with open(file_path, 'r') as file: + for line in file: + line = line.rstrip('\n') + result = check_divisibility(line) + print(result) + except FileNotFoundError: + print(f'File "{file_path}" not found.') + + +file_path = 'test.in' +main(file_path) diff --git a/TaskE42/run.py b/TaskE42/run.py new file mode 100644 index 0000000..5125d46 --- /dev/null +++ b/TaskE42/run.py @@ -0,0 +1,13 @@ +import re + +def sprawdz_napis(napis): + warunek = re.compile(r'^NI+E{6,}!{3,}|^N+O{6,}!{3,}') + if warunek.match(napis): + print('yes') + else: + print('no') + +with open('test.in', 'r') as plik: + for linia in plik: + linia = linia.rstrip('\n') + sprawdz_napis(linia) diff --git a/TaskE44/run.py b/TaskE44/run.py new file mode 100644 index 0000000..292c1d8 --- /dev/null +++ b/TaskE44/run.py @@ -0,0 +1,18 @@ +import re + +def analizuj_wiersze(plik): + with open(plik, 'r', encoding='utf-8') as file: + for line in file: + line = line.rstrip() + regex = r'^([A-ZĆŁÓŚŹŻ][a-ząćęłńóśźż]*a)\s([A-ZĆŁÓŚŹŻ][a-ząćęłńóśźż]{1,})$' + match = re.match(regex, line) + if match: + imie, nazwisko = match.groups() + if not re.match(r'^(Kosma|Jarema)$', imie): + print(nazwisko) + else: + print("") + else: + print("") + +analizuj_wiersze("test.in")