This commit is contained in:
HOME-VM-TOSCHOOL 2023-12-10 17:21:22 +01:00
parent 92f076743d
commit e4500a95f9

37
TaskD01/run.py Normal file
View File

@ -0,0 +1,37 @@
import re
file_name: str = "simple"
def find_hamlet_lines(text: str) -> list[str]:
# Define the regular expression pattern
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)]
return hamlet_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_hamlet_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")