Compare commits

...

6 Commits

Author SHA1 Message Date
HOME-VM-TOSCHOOL
0188af8be3 Task E05 2023-12-10 18:47:03 +01:00
HOME-VM-TOSCHOOL
54cb1d191f Delete comments 2023-12-10 17:55:32 +01:00
HOME-VM-TOSCHOOL
3ece132738 Task D04 2023-12-10 17:55:24 +01:00
HOME-VM-TOSCHOOL
16c8d13f3c small rewrites 2023-12-10 17:44:59 +01:00
HOME-VM-TOSCHOOL
c98f9027e0 Task D03 2023-12-10 17:32:32 +01:00
HOME-VM-TOSCHOOL
71e2825c81 Task D02 2023-12-10 17:32:26 +01:00
5 changed files with 144 additions and 5 deletions

View File

@ -4,14 +4,11 @@ file_name: str = "simple"
def find_hamlet_lines(text: str) -> list[str]: def find_hamlet_lines(text: str) -> list[str]:
# Define the regular expression pattern pattern = re.compile(r"Hamlet", re.IGNORECASE)
pattern = re.compile(r".*Hamlet.*", re.IGNORECASE)
# Split the text into lines
lines = text.split("\n") lines = text.split("\n")
# Use the regular expression to find lines containing "Hamlet" hamlet_lines = [line for line in lines if re.search(pattern, line)]
hamlet_lines = [line for line in lines if re.match(pattern, line)]
return hamlet_lines return hamlet_lines

34
TaskD02/run.py Normal file
View File

@ -0,0 +1,34 @@
import re
file_name: str = "simple"
def find_pies_lines(text: str) -> list[str]:
pattern = re.compile(r"\bpies\b", re.IGNORECASE)
lines = text.split("\n")
pies_lines = [line for line in lines if re.search(pattern, line)]
return pies_lines
with open(file_name + ".in", "r", newline="", encoding="utf8") as file:
text = file.read()
with open(file_name + ".exp", "r", newline="", encoding="utf8") as file:
expected = [line.rstrip() for line in file.readlines()]
found_lines = find_pies_lines(text)
mistake = False
for line in expected:
if line in found_lines:
print(f"{line}")
else:
print(f"NO: {line}")
mistake = True
if mistake:
print("ERROR")

34
TaskD03/run.py Normal file
View File

@ -0,0 +1,34 @@
import re
file_name: str = "simple"
def find_dates_1900_to_1999(text):
pattern = re.compile(r"19\d{2} r\.", re.IGNORECASE)
lines = text.split("\n")
date_lines = [line for line in lines if re.search(pattern, line)]
return date_lines
with open(file_name + ".in", "r", newline="", encoding="utf8") as file:
text = file.read()
with open(file_name + ".exp", "r", newline="", encoding="utf8") as file:
expected = [line.rstrip() for line in file.readlines()]
found_lines = find_dates_1900_to_1999(text)
mistake = False
for line in expected:
if line in found_lines:
print(f"{line}")
else:
print(f"NO: {line}")
mistake = True
if mistake:
print("ERROR")

33
TaskD04/run.py Normal file
View File

@ -0,0 +1,33 @@
import re
file_name: str = "simple"
def find_maximum_digit_substrings(text):
pattern = re.compile(r"\d+")
matches = pattern.findall(text)
result = " ".join(matches)
return result
with open(file_name + ".in", "r", newline="", encoding="utf8") as file:
text = file.read()
with open(file_name + ".exp", "r", newline="", encoding="utf8") as file:
expected = [line.rstrip() for line in file.readlines()]
found_lines = find_maximum_digit_substrings(text)
mistake = False
for line in expected:
if line in found_lines:
print(f"{line}")
else:
print(f"NO: {line}")
mistake = True
if mistake:
print("ERROR")

41
TaskE05/run.py Normal file
View File

@ -0,0 +1,41 @@
import re
FILE_NAME = "test"
MODE = "input"
def is_acronym(line):
acronym_pattern = re.compile(r"\b(?:PCMCIA|WYSIWYG|[A-Z]{2,5})\b")
if re.search(acronym_pattern, line):
return "yes"
else:
return "no"
if MODE == "test":
with open(FILE_NAME + ".in", "r", newline="", encoding="utf8") as file:
text = [line.rstrip() for line in file.readlines()]
with open(FILE_NAME + ".exp", "r", newline="", encoding="utf8") as file:
expected = [line.rstrip() for line in file.readlines()]
out: list[str] = []
for line in text:
out.append(is_acronym(line))
for ind, found in enumerate(out):
if found == expected[ind]:
print(found)
else:
print("ERROR")
elif MODE == "input":
line = input("Enter a line: ")
# Check if the line is an acronym and print 'yes' or 'no'
if is_acronym(line) == "yes":
print("yes")
else:
print("no")