-
Notifications
You must be signed in to change notification settings - Fork 7
/
rush_b.py
96 lines (86 loc) · 2.79 KB
/
rush_b.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
import os
import json
import signal
import time
def check_answer(a1: str, a2: str):
if a1 == a2:
return True
if a1.upper() == a2.upper():
return True
b1 = a1.upper().replace("1", "A").replace("2", "B").replace("3", "C").replace("4", "D")\
.replace("对", "A").replace("错", "B").replace("T", "A").replace("F", "B")
b2 = a2.upper().replace("1", "A").replace("2", "B").replace("3", "C").replace("4", "D")\
.replace("对", "A").replace("错", "B").replace("T", "A").replace("F", "B")
if b1 == b2:
return True
return False
do_what = "马克思主义基本原理题库.json"
problems = []
# 跳过个数
bypass_count = 0
# 只做错题?
only_do_error = False
# 错误阈值
error_threshold = 1
# 是否清屏
do_clear = False
def save_exit(signum, frame):
with open("process.json", "w") as f:
f.write(json.dumps(problems, ensure_ascii=False))
exit(0)
signal.signal(signal.SIGINT, save_exit)
signal.signal(signal.SIGTERM, save_exit)
if os.path.exists("process.json"):
with open("process.json", "r") as f:
problems = json.loads(f.read())
else:
with open(do_what, "r", encoding='UTF-8') as f:
problems = json.loads(f.read())
for pid, problem in enumerate(problems):
if pid < bypass_count:
continue
if only_do_error:
try:
if problem['error_times'] < error_threshold:
continue
except KeyError:
continue
try:
if check_answer(problem['answer'], problem['my_answer']):
continue
except KeyError:
pass
print("[%s]第%d题:\n" % (problem['type'].replace("题", ""), pid))
print(problem['problem'])
if problem['type'] != "判断题":
print(problem['A'])
print(problem['B'])
print(problem['C'])
print(problem['D'])
my_answer = input()
if my_answer.upper() == "SAVE":
with open("process.json", "w") as f:
f.write(json.dumps(problems, ensure_ascii=False))
my_answer = input()
if my_answer.upper() == "QUIT":
with open("process.json", "w") as f:
f.write(json.dumps(problems, ensure_ascii=False))
exit(0)
problems[pid]['my_answer'] = my_answer
if check_answer(problem['answer'], my_answer):
print("\033[32m答对了!\033[0m\n\n\n")
if do_clear:
time.sleep(1)
os.system("clear")
else:
print("\033[31m答错了!\033[0m")
print("正确答案:\033[32m" + problem['answer'] + "\033[0m")
print("我的答案:\033[31m" + my_answer + "\033[0m")
try:
problems[pid]['error_times'] += 1
except KeyError:
problems[pid]['error_times'] = 1
input()
print("\n\n\n")
if do_clear:
os.system("clear")