zadania E

This commit is contained in:
Wojtek 2024-01-19 20:41:55 +01:00
parent 53d4a43e16
commit fe915f67c3
13 changed files with 194 additions and 0 deletions

14
TaskE01/run.py Normal file
View File

@ -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)

14
TaskE02/run.py Normal file
View File

@ -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("<NONE>")
file_path = 'TaskE02/test.in'
extract_digits(file_path)

14
TaskE03/run.py Normal file
View File

@ -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)

14
TaskE04/run.py Normal file
View File

@ -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)

14
TaskE05/run.py Normal file
View File

@ -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)

14
TaskE06/run.py Normal file
View File

@ -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)

14
TaskE07/run.py Normal file
View File

@ -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)

14
TaskE08/run.py Normal file
View File

@ -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)

14
TaskE09/run.py Normal file
View File

@ -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)

14
TaskE10/run.py Normal file
View File

@ -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)

18
TaskE16/run.py Normal file
View File

@ -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)

20
TaskE43/run.py Normal file
View File

@ -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)

16
TaskE48/run.py Normal file
View File

@ -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)