From f95ed77b3fbb4b6e5d1643db823fcaf97ff9daa9 Mon Sep 17 00:00:00 2001 From: Albert Tan Date: Tue, 7 Mar 2023 20:18:29 +0800 Subject: v0.0 --- review_it.py | 80 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 80 insertions(+) create mode 100644 review_it.py 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) -- cgit v1.2.3 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 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 From 92280a138399fb070b713fd14cb04af317be5658 Mon Sep 17 00:00:00 2001 From: Albert Tan Date: Tue, 7 Mar 2023 20:19:22 +0800 Subject: v1.1 --- review_it.py | 25 +++++++++++++++++++------ 1 file changed, 19 insertions(+), 6 deletions(-) diff --git a/review_it.py b/review_it.py index 0d0b044..7d70e11 100644 --- a/review_it.py +++ b/review_it.py @@ -1,11 +1,9 @@ ''' Updated: -- Subtitles added -- Support all files with the same major version -- Slightly better output lines +- More flexibility when judging whether answer is correct To be updated: -- Better ways of reminding input +- Better ways to check syntax - Let user judge whether answer is correct - Zero / single / plural in final output - Remove unnecessary spaces or line breaks in input file @@ -13,6 +11,7 @@ To be updated: - 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 +- Consider to use json input file - Graphic user interface - Another program to help create related input file - Optimize @@ -21,19 +20,30 @@ To be updated: try: import re + import difflib def check_string(line): return bool(re.match("[!#-~] [\w\d\s]*", line)) + def compare_string(answer, response): + diff = difflib.ndiff(answer, response) + diff_count = 0 + for line in diff: + if line[0] != " ": + diff_count += 1 + return 1 - (diff_count / len(response)) + + file_name = input("Enter file name (with postfix) >> ") if file_name == "": - file_name = "test_1.0.rvwt" + file_name = "test_1.1.rvwt" with open(file_name) as f: data = f.readlines() count_prompts = 0 count_correct = 0 + correct_param = 0.66 incorrect = [] @@ -66,6 +76,9 @@ try: if response.lower() == answer.lower(): print("Correct") count_correct += 1 + elif compare_string(response.lower(), answer.lower()) >= correct_param: + print(f"Probably correct: answer is '{answer}', similarity {round(compare_string(response.lower(), answer.lower()), 4)*100}%") + count_correct += 1 else: print(f"Incorrect: answer is '{answer}'") incorrect.append((prompt, answer)) @@ -89,4 +102,4 @@ except Exception as e: except KeyboardInterrupt: print("\nProcess quitted") except BaseException as e: - print("\n" + str(e)) + print("\nException: " + str(e)) -- cgit v1.2.3 From 9afc956d01fcf70070100ae230bb9c102289e05a Mon Sep 17 00:00:00 2001 From: Albert Tan Date: Tue, 7 Mar 2023 20:19:27 +0800 Subject: v1.2 --- review_it.py | 63 +++++++++++++++++++++++++++++++++++++++--------------------- 1 file changed, 41 insertions(+), 22 deletions(-) diff --git a/review_it.py b/review_it.py index 7d70e11..1db5d38 100644 --- a/review_it.py +++ b/review_it.py @@ -1,11 +1,12 @@ ''' Updated: -- More flexibility when judging whether answer is correct - -To be updated: - Better ways to check syntax - Let user judge whether answer is correct - Zero / single / plural in final output + +To be updated: +- Learn answers +- Make orders not matter - Remove unnecessary spaces or line breaks in input file - Better ways to handle each line - Answer judged correct if contains keyword @@ -24,33 +25,33 @@ try: def check_string(line): - return bool(re.match("[!#-~] [\w\d\s]*", line)) + return bool(re.match("([-~] [\w\d\s\?\.\"\(\)\[\]\{\}!,;'/]*\Z)|(! version: \d+\.?\d*\s?\Z)|(# [\w\d\s\?\.\"\(\)\[\]\{\}!,;'/]*: [\w\d\s\?\.\"\(\)\[\]\{\}!,;'/]*\Z)", line)) def compare_string(answer, response): - diff = difflib.ndiff(answer, response) + diff = list(difflib.ndiff(answer, response)) diff_count = 0 for line in diff: if line[0] != " ": diff_count += 1 - return 1 - (diff_count / len(response)) + return round(1 - (diff_count / len(diff)), 4)*100 file_name = input("Enter file name (with postfix) >> ") if file_name == "": - file_name = "test_1.1.rvwt" + file_name = "test_1.2.rvwt" with open(file_name) as f: data = f.readlines() count_prompts = 0 count_correct = 0 - correct_param = 0.66 + correct_param = 0.8 incorrect = [] if len(data) == 0: raise Exception("Error: file empty") - - if data.pop(0).split(".")[0] != "! version: 1": + + if data.pop(0).split(".")[0].replace("\n", "") != "! version: 1": raise Exception("Error: file version not provided or does not match") for line_index in range(len(data)): @@ -68,8 +69,6 @@ try: 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 + ">> ") @@ -77,29 +76,49 @@ try: print("Correct") count_correct += 1 elif compare_string(response.lower(), answer.lower()) >= correct_param: - print(f"Probably correct: answer is '{answer}', similarity {round(compare_string(response.lower(), answer.lower()), 4)*100}%") - count_correct += 1 + print(f"Probably correct: answer is '{answer}', similarity {round(compare_string(response.lower(), answer.lower()), 4)}%") + judge = input("Is your answer correct? [y/n] ").lower() + if judge == 'n': + incorrect.append((prompt, answer)) + else: + count_correct += 1 + if judge != "y": + print("Warning: invalid input, answer judged as correct") else: - print(f"Incorrect: answer is '{answer}'") - incorrect.append((prompt, answer)) + print(f"Probably incorrect: answer is '{answer}', similarity {round(compare_string(response.lower(), answer.lower()), 4)}%") + judge = input("Is your answer correct? [y/n] ").lower() + if judge == 'y': + count_correct += 1 + else: + incorrect.append((prompt, answer)) + if judge != "n": + print("Warning: invalid input, answer judged as incorrect") else: continue - - 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 <= 1: + print(f"\n\nOut of {count_prompts} question, ", end="") + else: + print(f"\n\nOut of {count_prompts} questions, ", end="") + if count_correct <= 1: + print(f"{count_correct} was answered correctly, ", end="") + else: + print(f"{count_correct} were answered correctly, ", end="") + print(f"which is {round(count_correct / count_prompts, 4)*100}%. ") if count_prompts == count_correct: print("Congratulations for finishing perfectly! ") else: - print(f"The questions with incorrect responses are listed below: \n") + if count_prompts - count_correct <= 1: + print(f"The question with incorrect response is listed below: \n") + 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("\n" + str(e)) + print("\nException: " + str(e)) except KeyboardInterrupt: print("\nProcess quitted") -except BaseException as e: - print("\nException: " + str(e)) -- cgit v1.2.3 From d56644ade91ef0503911edb13b209f8bdeadc3ee Mon Sep 17 00:00:00 2001 From: Andrew Date: Tue, 7 Mar 2023 20:28:50 +0800 Subject: Ignore all data files. --- .gitignore | 1 + 1 file changed, 1 insertion(+) create mode 100644 .gitignore diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..3947ddb --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +*.rvwt -- cgit v1.2.3 From fd0969a3eb17b6a0561ba3ab8196390db02f717b Mon Sep 17 00:00:00 2001 From: Albert Tan Date: Thu, 13 Apr 2023 20:36:46 +0800 Subject: 2.0 --- review_it.py | 124 ------------------------------------- review_it_2.0.py | 182 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 182 insertions(+), 124 deletions(-) delete mode 100644 review_it.py create mode 100644 review_it_2.0.py diff --git a/review_it.py b/review_it.py deleted file mode 100644 index 1db5d38..0000000 --- a/review_it.py +++ /dev/null @@ -1,124 +0,0 @@ -''' -Updated: -- Better ways to check syntax -- Let user judge whether answer is correct -- Zero / single / plural in final output - -To be updated: -- Learn answers -- Make orders not matter -- 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 -- Consider to use json input file -- Graphic user interface -- Another program to help create related input file -- Optimize -''' - -try: - - import re - import difflib - - - def check_string(line): - return bool(re.match("([-~] [\w\d\s\?\.\"\(\)\[\]\{\}!,;'/]*\Z)|(! version: \d+\.?\d*\s?\Z)|(# [\w\d\s\?\.\"\(\)\[\]\{\}!,;'/]*: [\w\d\s\?\.\"\(\)\[\]\{\}!,;'/]*\Z)", line)) - - - def compare_string(answer, response): - diff = list(difflib.ndiff(answer, response)) - diff_count = 0 - for line in diff: - if line[0] != " ": - diff_count += 1 - return round(1 - (diff_count / len(diff)), 4)*100 - - - file_name = input("Enter file name (with postfix) >> ") - if file_name == "": - file_name = "test_1.2.rvwt" - with open(file_name) as f: - data = f.readlines() - count_prompts = 0 - count_correct = 0 - correct_param = 0.8 - incorrect = [] - - - if len(data) == 0: - raise Exception("Error: file empty") - - if data.pop(0).split(".")[0].replace("\n", "") != "! 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}'") - - for line_index in range(len(data)): - line = data[line_index] - 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(":") - prompt = line[0] - answer = line[1][1:-1] - response = input(prompt + ">> ") - if response.lower() == answer.lower(): - print("Correct") - count_correct += 1 - elif compare_string(response.lower(), answer.lower()) >= correct_param: - print(f"Probably correct: answer is '{answer}', similarity {round(compare_string(response.lower(), answer.lower()), 4)}%") - judge = input("Is your answer correct? [y/n] ").lower() - if judge == 'n': - incorrect.append((prompt, answer)) - else: - count_correct += 1 - if judge != "y": - print("Warning: invalid input, answer judged as correct") - else: - print(f"Probably incorrect: answer is '{answer}', similarity {round(compare_string(response.lower(), answer.lower()), 4)}%") - judge = input("Is your answer correct? [y/n] ").lower() - if judge == 'y': - count_correct += 1 - else: - incorrect.append((prompt, answer)) - if judge != "n": - print("Warning: invalid input, answer judged as incorrect") - else: - continue - - if count_prompts <= 1: - print(f"\n\nOut of {count_prompts} question, ", end="") - else: - print(f"\n\nOut of {count_prompts} questions, ", end="") - if count_correct <= 1: - print(f"{count_correct} was answered correctly, ", end="") - else: - print(f"{count_correct} were answered correctly, ", end="") - print(f"which is {round(count_correct / count_prompts, 4)*100}%. ") - - if count_prompts == count_correct: - print("Congratulations for finishing perfectly! ") - else: - if count_prompts - count_correct <= 1: - print(f"The question with incorrect response is listed below: \n") - 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("\nException: " + str(e)) -except KeyboardInterrupt: - print("\nProcess quitted") diff --git a/review_it_2.0.py b/review_it_2.0.py new file mode 100644 index 0000000..4aee6f0 --- /dev/null +++ b/review_it_2.0.py @@ -0,0 +1,182 @@ +""" +Updated: +- Add line-type 'note' with syntax '=' +- Add line-type 'list' with syntax '&' +- Change syntax of line-type 'title' to '+' instead of '-' +- Remove unnecessary spaces in input file + +To be updated: +- Learn answers +- Remove unnecessary line breaks in input file +- Answer judged correct if contains keyword +- Title and subtitle also printed if answer in the section is incorrect +- Consider to use json input file +- Graphic user interface +- Another program to help create related input file +- Optimize +""" + +try: + + import re + import difflib + + def check_string(line): + string = r"[\w\d\s\?\.\"\(\)\[\]\{\}\-!,;'/]*" + return bool( + re.match( + f"([+~=] {string}\Z)|(! version: \d+\.?\d*\s?\Z)|(# {string}: {string}\Z)|(& ({string}: )+{string}\Z)", + line, + ) + ) + + def compare_string(answer, response): + diff = list(difflib.ndiff(answer, response)) + diff_count = 0 + for line in diff: + if line[0] != " ": + diff_count += 1 + return round(1 - (diff_count / len(diff)), 4) * 100 + + file_name = input("Enter file name (with postfix) >> ") + if file_name == "": + file_name = "test_2.0.rvwt" + with open(file_name) as f: + data = f.readlines() + count_prompts = 0 + count_correct = 0 + correct_param = 70 + incorrect = [] + + if len(data) == 0: + raise Exception("Error: file empty") + + if data.pop(0).split(".")[0].replace("\n", "") != "! version: 2": + 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:].replace("\n", "") + print("\n\n- " + line + " -\n") + elif line[0] == "~": + line = line[2:].replace("\n", "") + print("\n" + line + "\n") + elif line[0] == "=": + line = line[2:].replace("\n", "") + print(line) + elif line[0] == "#": + count_prompts += 1 + line = line[2:].split(":") + prompt = line[0] + answer = line[1][1:-1] + if prompt != "": + prompt += " " + response = input(prompt + ">> ") + if response.lower() == answer.lower(): + print("Correct") + count_correct += 1 + elif compare_string(response.lower(), answer.lower()) >= correct_param: + print( + f"Probably correct: answer is '{answer}', similarity {round(compare_string(response.lower(), answer.lower()), 4)}%" + ) + judge = input("Is your answer correct? [[y]/n] ").lower() + if judge == "n": + incorrect.append((prompt, answer)) + else: + count_correct += 1 + if judge != "y": + print("Warning: invalid input, answer judged as correct") + else: + print( + f"Probably incorrect: answer is '{answer}', similarity {round(compare_string(response.lower(), answer.lower()), 4)}%" + ) + judge = input("Is your answer correct? [y/[n]] ").lower() + if judge == "y": + count_correct += 1 + else: + incorrect.append((prompt, answer)) + if judge != "n": + print("Warning: invalid input, answer judged as incorrect") + elif line[0] == "&": + line = line[2:].split(":") + prompt = line.pop(0) + answers = list(map(lambda x: x[1:].lower().replace("\n", ""), line)) + items = len(answers) + count_prompts += items + correct_answers = 1 + answers_max = items + print(prompt) + while answers_max >= correct_answers: + response = input(f"{correct_answers}/{answers_max} >> ") + if response == "": + break + elif response.lower() in answers: + print("Correct") + answers.pop(answers.index(response.lower())) + correct_answers += 1 + else: + max_similarity = 0 + max_index = 0 + for answer in answers: + if compare_string(response.lower(), answer) > max_similarity: + max_similarity = compare_string(response.lower(), answer) + max_index = answers.index(answer) + if max_similarity >= correct_param: + print( + f"Probably correct: closest answer is '{answers[max_index]}', similarity {round(compare_string(response.lower(), answers[max_index]), 4)}%" + ) + judge = input("Is your answer correct? [[y]/n] ").lower() + if judge == "n": + answers_max -= 1 + else: + answers.pop(max_index) + correct_answers += 1 + if judge != "y": + print("Warning: invalid input, answer judged as correct") + else: + print("Probably incorrect") + answers_max -= 1 + if len(answers) != 0: + print("You didn't get the following answers correct: ", end="") + for answer in answers: + incorrect.append((prompt, answer)) + print("'" + answer+ "' ", end="") + count_correct += correct_answers - 1 + if len(answers) != 0: + print() + else: + continue + + if count_prompts <= 1: + print(f"\n\nOut of {count_prompts} question, ", end="") + else: + print(f"\n\nOut of {count_prompts} questions, ", end="") + if count_correct <= 1: + print(f"{count_correct} was answered correctly, ", end="") + else: + print(f"{count_correct} were answered correctly, ", end="") + print(f"which is {round(count_correct / count_prompts * 100, 2)}%. ") + + if count_prompts == count_correct: + print("Congratulations for finishing perfectly! ") + else: + if count_prompts - count_correct <= 1: + print(f"The question with incorrect response is listed below: \n") + 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("\nException: " + str(e)) +except KeyboardInterrupt: + print("\nProcess quitted") -- cgit v1.2.3