Task D03
This commit is contained in:
parent
71e2825c81
commit
c98f9027e0
39
TaskD03/run.py
Normal file
39
TaskD03/run.py
Normal file
@ -0,0 +1,39 @@
|
|||||||
|
import re
|
||||||
|
|
||||||
|
file_name: str = "simple"
|
||||||
|
|
||||||
|
|
||||||
|
def find_dates_1900_to_1999(text):
|
||||||
|
# Define the regular expression pattern
|
||||||
|
pattern = re.compile(r".*19\d{2} r\..*", re.IGNORECASE)
|
||||||
|
|
||||||
|
# Split the text into lines
|
||||||
|
lines = text.split("\n")
|
||||||
|
|
||||||
|
# Use the regular expression to find lines containing dates from 1900 to 1999
|
||||||
|
date_lines = [
|
||||||
|
line for _, line in enumerate(lines, start=1) if re.match(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")
|
Loading…
Reference in New Issue
Block a user