zadania E
This commit is contained in:
parent
b2762576a2
commit
e067a250ea
13
TaskE04/run.py
Normal file
13
TaskE04/run.py
Normal file
@ -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())
|
@ -10,3 +10,5 @@
|
|||||||
556 345 667
|
556 345 667
|
||||||
556 345 6675
|
556 345 6675
|
||||||
556 345-667
|
556 345-667
|
||||||
|
555 555 555
|
||||||
|
555 555 555
|
28
TaskE11/run.py
Normal file
28
TaskE11/run.py
Normal file
@ -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)
|
13
TaskE42/run.py
Normal file
13
TaskE42/run.py
Normal file
@ -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)
|
18
TaskE44/run.py
Normal file
18
TaskE44/run.py
Normal file
@ -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("<NONE>")
|
||||||
|
else:
|
||||||
|
print("<NONE>")
|
||||||
|
|
||||||
|
analizuj_wiersze("test.in")
|
Loading…
Reference in New Issue
Block a user