Compare commits
6 Commits
e4500a95f9
...
0188af8be3
Author | SHA1 | Date | |
---|---|---|---|
|
0188af8be3 | ||
|
54cb1d191f | ||
|
3ece132738 | ||
|
16c8d13f3c | ||
|
c98f9027e0 | ||
|
71e2825c81 |
@ -4,14 +4,11 @@ file_name: str = "simple"
|
||||
|
||||
|
||||
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")
|
||||
|
||||
# Use the regular expression to find lines containing "Hamlet"
|
||||
hamlet_lines = [line for line in lines if re.match(pattern, line)]
|
||||
hamlet_lines = [line for line in lines if re.search(pattern, line)]
|
||||
|
||||
return hamlet_lines
|
||||
|
||||
|
34
TaskD02/run.py
Normal file
34
TaskD02/run.py
Normal 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
34
TaskD03/run.py
Normal 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
33
TaskD04/run.py
Normal 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
41
TaskE05/run.py
Normal 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")
|
Loading…
Reference in New Issue
Block a user