From a0e11a7b74fd7960c21961685fbca640e0329399 Mon Sep 17 00:00:00 2001 From: Albert Tan Date: Tue, 7 Mar 2023 20:19:15 +0800 Subject: v1.0 --- review_it.py | 30 +++++++++++++++--------------- 1 file changed, 15 insertions(+), 15 deletions(-) diff --git a/review_it.py b/review_it.py index b13671f..0d0b044 100644 --- a/review_it.py +++ b/review_it.py @@ -1,12 +1,10 @@ ''' Updated: -- Choosing input file +- Subtitles added +- Support all files with the same major version - 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 judge whether answer is correct - Zero / single / plural in final output @@ -26,12 +24,12 @@ try: def check_string(line): - return bool(re.match("[!#-] [\w\d\s]*", line)) + return bool(re.match("[!#-~] [\w\d\s]*", line)) file_name = input("Enter file name (with postfix) >> ") if file_name == "": - file_name = "test_0.1.rvwt" + file_name = "test_1.0.rvwt" with open(file_name) as f: data = f.readlines() count_prompts = 0 @@ -42,20 +40,22 @@ try: if len(data) == 0: raise Exception("Error: file empty") - if data.pop(0) != "! version: 0.1\n": + if data.pop(0).split(".")[0] != "! version: 1": 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("\n" + line) - elif line[0] == "-": + if line[0] == "-": + line = line[2:].replace("\n", "") + print("\n\n- " + line + " -\n") + if line[0] == "~": + line = line[2:].replace("\n", "") + print("\n" + line + "\n") + elif line[0] == "#": count_prompts += 1 line = line[2:].split(":") if len(line) != 2: @@ -64,16 +64,16 @@ try: answer = line[1][1:-1] response = input(prompt + ">> ") if response.lower() == answer.lower(): - print("Correct\n") + print("Correct") count_correct += 1 else: - print(f"Incorrect: answer is '{answer}'\n") + print(f"Incorrect: answer is '{answer}'") incorrect.append((prompt, answer)) else: continue - print(f"\nOut of {count_prompts} questions, {count_correct} were answered correctly, which is {round(count_correct / count_prompts, 4)*100}%. ") + print(f"\n\nOut of {count_prompts} questions, {count_correct} were answered correctly, which is {round(count_correct / count_prompts, 4)*100}%. ") if count_prompts == count_correct: print("Congratulations for finishing perfectly! ") -- cgit v1.2.3