summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlbert Tan <s22505@ykpaoschool.cn>2023-03-07 20:19:15 +0800
committerAlbert Tan <s22505@ykpaoschool.cn>2023-03-07 20:19:15 +0800
commita0e11a7b74fd7960c21961685fbca640e0329399 (patch)
tree38b3da969829bf8d3ca031f994c946ad94a523da
parent4c451ab07ba92e9ba3ec03d024963f0224c1100a (diff)
downloadreview_it-a0e11a7b74fd7960c21961685fbca640e0329399.tar.gz
review_it-a0e11a7b74fd7960c21961685fbca640e0329399.zip
v1.0
-rw-r--r--review_it.py30
1 files 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! ")