From 4c451ab07ba92e9ba3ec03d024963f0224c1100a Mon Sep 17 00:00:00 2001 From: Albert Tan Date: Tue, 7 Mar 2023 20:18:47 +0800 Subject: v0.1 --- review_it.py | 40 ++++++++++++++++++++++++++-------------- 1 file changed, 26 insertions(+), 14 deletions(-) diff --git a/review_it.py b/review_it.py index 2fa83ee..b13671f 100644 --- a/review_it.py +++ b/review_it.py @@ -1,7 +1,13 @@ ''' +Updated: +- Choosing input file +- Slightly better output lines +- Congratulations if full mark + To be updated: +- Subtitles below titles +- Support files with the same major version - Better ways of reminding input -- Let user choose input file - Let user judge whether answer is correct - Zero / single / plural in final output - Remove unnecessary spaces or line breaks in input file @@ -16,7 +22,6 @@ To be updated: try: - import re @@ -24,29 +29,32 @@ try: return bool(re.match("[!#-] [\w\d\s]*", line)) - file_name = "test_0.0.rvwt" + file_name = input("Enter file name (with postfix) >> ") + if file_name == "": + file_name = "test_0.1.rvwt" with open(file_name) as f: data = f.readlines() count_prompts = 0 count_correct = 0 - incorrect = {} + incorrect = [] if len(data) == 0: raise Exception("Error: file empty") - if data.pop(0) != "! version: 0.0\n": + if data.pop(0) != "! version: 0.1\n": raise Exception("Error: file version not provided or does not match") for line_index in range(len(data)): if not check_string(data[line_index]): raise Exception(f"Error: invalid syntax at line {line_index+2} of file '{file_name}'") + print() for line_index in range(len(data)): line = data[line_index] if line[0] == "#": line = line[2:] - print(line) + print("\n" + line) elif line[0] == "-": count_prompts += 1 line = line[2:].split(":") @@ -60,21 +68,25 @@ try: count_correct += 1 else: print(f"Incorrect: answer is '{answer}'\n") - incorrect[prompt] = answer + incorrect.append((prompt, answer)) else: continue - print(f"Out of {count_prompts} questions, {count_correct} were answered correctly. ") - print(f"The questions with incorrect responses are listed below: \n") + print(f"\nOut of {count_prompts} questions, {count_correct} were answered correctly, which is {round(count_correct / count_prompts, 4)*100}%. ") - for i in incorrect.keys(): - print(i + "-> " + incorrect[i]) + if count_prompts == count_correct: + print("Congratulations for finishing perfectly! ") + else: + print(f"The questions with incorrect responses are listed below: \n") + for line in incorrect: + (prompt, answer) = line + print(prompt + "-> " + answer) except Exception as e: - print(e) + print("\n" + str(e)) except KeyboardInterrupt: - print("Process quitted") + print("\nProcess quitted") except BaseException as e: - print(e) + print("\n" + str(e)) -- cgit v1.2.3