jfz-2023-s473555/TaskE29/run.py
HOME-VM-TOSCHOOL d6a99fbae7 Task E29
2024-01-08 04:36:05 +01:00

42 lines
946 B
Python

import re
FILE_NAME = "test"
MODE = "test"
def find_fitting(line):
acronym_pattern = re.compile(r"^(?!\d)\w+$")
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(find_fitting(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 find_fitting(line) == "yes":
print("yes")
else:
print("no")