Task E05
This commit is contained in:
parent
54cb1d191f
commit
0188af8be3
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