From d6a99fbae76cd41308f0d0ebf4b2f3441d8925fd Mon Sep 17 00:00:00 2001 From: HOME-VM-TOSCHOOL Date: Mon, 8 Jan 2024 04:36:05 +0100 Subject: [PATCH] Task E29 --- TaskE29/run.py | 41 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) create mode 100644 TaskE29/run.py diff --git a/TaskE29/run.py b/TaskE29/run.py new file mode 100644 index 0000000..da86f7f --- /dev/null +++ b/TaskE29/run.py @@ -0,0 +1,41 @@ +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")