summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlbert Tan <s22505@ykpaoschool.cn>2023-03-07 20:18:47 +0800
committerAlbert Tan <s22505@ykpaoschool.cn>2023-03-07 20:18:47 +0800
commit4c451ab07ba92e9ba3ec03d024963f0224c1100a (patch)
tree99bb135aed87628a439e54077ba5b7507983baeb
parentf95ed77b3fbb4b6e5d1643db823fcaf97ff9daa9 (diff)
downloadreview_it-4c451ab07ba92e9ba3ec03d024963f0224c1100a.tar.gz
review_it-4c451ab07ba92e9ba3ec03d024963f0224c1100a.zip
v0.1
-rw-r--r--review_it.py40
1 files 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))