summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlbert Tan <s22505@ykpaoschool.cn>2023-03-07 20:18:29 +0800
committerAlbert Tan <s22505@ykpaoschool.cn>2023-03-07 20:18:29 +0800
commitf95ed77b3fbb4b6e5d1643db823fcaf97ff9daa9 (patch)
treeb2d34d9bbcfbd26371420ec0d97ed26ec4f9af10
downloadreview_it-f95ed77b3fbb4b6e5d1643db823fcaf97ff9daa9.tar.gz
review_it-f95ed77b3fbb4b6e5d1643db823fcaf97ff9daa9.zip
v0.0
-rw-r--r--review_it.py80
1 files changed, 80 insertions, 0 deletions
diff --git a/review_it.py b/review_it.py
new file mode 100644
index 0000000..2fa83ee
--- /dev/null
+++ b/review_it.py
@@ -0,0 +1,80 @@
+'''
+To be updated:
+- 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
+- Better ways to handle each line
+- Answer judged correct if contains keyword
+- Use something better than a dictionary to store incorrect answers
+- Title also printed if answer in the section is incorrect
+- Graphic user interface
+- Another program to help create related input file
+- Optimize
+'''
+
+try:
+
+
+ import re
+
+
+ def check_string(line):
+ return bool(re.match("[!#-] [\w\d\s]*", line))
+
+
+ file_name = "test_0.0.rvwt"
+ with open(file_name) as f:
+ data = f.readlines()
+ count_prompts = 0
+ count_correct = 0
+ incorrect = {}
+
+
+ if len(data) == 0:
+ raise Exception("Error: file empty")
+
+ if data.pop(0) != "! version: 0.0\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}'")
+
+ for line_index in range(len(data)):
+ line = data[line_index]
+ if line[0] == "#":
+ line = line[2:]
+ print(line)
+ elif line[0] == "-":
+ count_prompts += 1
+ line = line[2:].split(":")
+ if len(line) != 2:
+ raise Exception(f"Error: invalid syntax at line {line_index+2} of file '{file_name}'")
+ prompt = line[0]
+ answer = line[1][1:-1]
+ response = input(prompt + ">> ")
+ if response.lower() == answer.lower():
+ print("Correct\n")
+ count_correct += 1
+ else:
+ print(f"Incorrect: answer is '{answer}'\n")
+ incorrect[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")
+
+ for i in incorrect.keys():
+ print(i + "-> " + incorrect[i])
+
+
+except Exception as e:
+ print(e)
+except KeyboardInterrupt:
+ print("Process quitted")
+except BaseException as e:
+ print(e)