File size: 8,538 Bytes
984bdfe
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
6269e6e
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
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
import gradio as gr
import re

# 题目列表
questions = [
    "1. 37^(-42)=",
    "2. lim_{x→0} x³/(tanx - x)=",
    "3. cos x = x 的实根为 x=",
    "4. f(x)=(x-1)e^(x+1)+√(2x)+1/x-ln²x 的最小值为",
    "5. f(x)=x/6 + sinx/x 的极值点数量为",
    "6. y=(x-e)e^x+ln²(x+1)-√(x+1) 在(0,e1)处的切线在x轴上的截距为",
    "7. 点(1, 0)关于直线5x-2y+3=0的对称点为",
    "8. (2+3i)^7的虚部为",
    "9. arg(3+7i)/(9-4i)=(弧度制)",
    "10. 5!11! mod 998244353=",
    "11. C₃₇¹⁵=",
    "12. (x+2)^5除以x²+x+1的商(忽略余式)为",
    "13. 设f(x)=x⁴e^(x²)则f^(4)(x)/e^(x²)展开后x⁴的系数为",
    "14. 102233201和123456789的最大公约数为",
    "15. 2025的所有因数之和为",
    "16. ∑_{n=1}^∞ n^(-n)=",
    "17. ∫₀¹x^(-x)dx=",
    "18. ∑_{n=1}^{25}∏_{k=1}^n(1+1/k²)=",
    "19. (11,45,14)×(19,198,10)=",
    "20. 以(−2,−1,−1),(−1,1,3),(2,−4,1),(2,2,0)为顶点的四面体的体积为",
    "21. 点(1,0)到y=arctanx的距离为",
    "22. 5¹²+8¹²的所有质因数之和为",
    "23. 因式分解:x⁵-6x⁴+12x³-8x²-7x-1=",
    "24. 因式分解:a³b-3a³+a²b²+2ab²-6ab+2b³=",
    "25. √1,√2,√3,…,√2025的方差为",
    "26. 过(−2,−1),(−1,1),(0,2),(1,−2),(3,0)的二次曲线的离心率为",
    "27. x³-3x-5=0的复数根的实部为",
    "28. 已知六点(−2,−27),(−1,13),(0,5),(1,3),(2,−11),(3,−7),用最小二乘法拟合直线的相关系数为",
    "29. 以(−1,−1),(0,5),(6,2)为顶点的三角形外接圆半径为 其垂心坐标为",
    "30. (x+2)^4(3x²-5)(x²-6x-1)的展开式中x⁴的系数为",
    "31. 设X~N(0,0.5²),则P(-0.2≤X≤0.3)=",
    "32. 曲线y=2^x-x²(x∈[-2,4])的长度为",
    "33. 椭圆x²/5+y²/2=1的周长为",
    "34. 曲线ρ=1-sinθ在点(1,0)处的曲率为",
    "35. 曲线2x²+y²-5y+4=0和x²+2xy-3y²-2=0的所有公切线斜率之积为",
    "36. (13579 BD)₁₅转换为10进制是",
    "37. f(x)=1/(1-x-x²)在x=0处的泰勒展开的前6项为",
    "38. [2025,5202]中的质数数量为",
    "39. 已知a₁=2,aₙ₊₁=aₙ-1/aₙ,则a₂₀₂₅=",
    "40. 已知a₁=2,a₂=3,aₙ₊₂=aₙ₊₁-1/aₙ,则a₂₀₂₅=",
    "41. 冰雹猜想:从27开始,迭代得到1的最少次数为",
    "42. 已知a₁=0,a₂=1,aₙ₊₂=(n+1)(aₙ+aₙ₊₁),则a₄₀₉₆ mod 998244353=",
    "43. 已知f²(x)f'(x)=xe^x,f(2)=3,则f(0)=",
    "44. 已知某分子和分母均小于1000的分数约等于0.294663573085847,则该分数为",
    "45. 满足2ⁿ中不出现重复数字的最大正整数n为",
    "46. 已知a^a+b^b+c^c+d^d=abcd(abcd为1~9的正整数),则abcd=",
    "47. 100! mod 998244353=",
    "48. √(eπ)小数点后第37位是",
    "49. 已知f''(x)=2f(x)+x,f(0)=2,f'(0)=-1/2,则f(1)=",
    "50. 3^(4^5)的各位数字之和为"
]

# 答案列表(已按题目顺序整理并统一格式)
answers = [
    "1.3662e-66",        # 1
    "3",                  # 2
    "0.73909",            # 3
    "0.08027",            # 4
    "4",                  # 5
    "-1.6762",            # 6
    "(-1.7586,1.1034)",   # 7
    "4449",               # 8
    "1.5841",             # 9
    "797038588",          # 10
    "9364199760",         # 11
    "x³+9x²+30x+41",      # 12
    "492",                # 13
    "3607",               # 14
    "3751",               # 15
    "1.2913",             # 16
    "1.2913",             # 17
    "81.672",             # 18
    "(-2322,156,1323)",   # 19
    "15.833",             # 20
    "0.67234",            # 21
    "12691",              # 22
    "(x²-3x-1)(x³-3x²+4x+1)",  # 23
    "(a²+2b)(ab-3a+b²)",  # 24
    "112.34",             # 25
    "0.84984",            # 26
    "-1.1395",            # 27
    "0.09798",            # 28
    "3.9841 (0.92308,2.8462)",  # 29
    "-475",               # 30
    "0.38117",            # 31
    "10.750",             # 32
    "11.613",             # 33
    "1.0607",             # 34
    "176",                # 35
    "13947703",           # 36
    "1+x+2x²+3x³+5x⁴+8x⁵", # 37
    "386",                # 38
    "-35.709",            # 39
    "-125.93",            # 40
    "111",                # 41
    "641190802",          # 42
    "1.2238",             # 43
    "127/431",            # 44
    "29",                 # 45
    "3435",               # 46
    "35305197",           # 47
    "3",                  # 48
    "3.8564",             # 49
    "2250"                # 50
]

def verify_answers(*user_answers):
    """验证用户答案并返回评分结果"""
    results = []
    score = 0
    for idx, (user_ans, correct_ans) in enumerate(zip(user_answers, answers)):
        is_correct = False
        user_ans = str(user_ans).strip()
        
        # 数值型答案验证(保留五位有效数字)
        if re.match(r'^-?\d+\.\d+e?-?\d*$', correct_ans) or re.match(r'^-?\d+\.\d+$', correct_ans):
            try:
                # 统一科学计数法格式
                user_num = float(user_ans.replace('×10^', 'e').replace('^', 'e'))
                correct_num = float(correct_ans.replace('×10^', 'e').replace('^', 'e'))
                # 计算有效数字位数
                sig_figs = 5 - (0 if correct_num == 0 else len(str(int(abs(correct_num)))))
                user_rounded = round(user_num, sig_figs) if sig_figs > 0 else int(round(user_num))
                correct_rounded = round(correct_num, sig_figs) if sig_figs > 0 else int(round(correct_num))
                is_correct = abs(user_rounded - correct_rounded) < 1e-4
            except:
                pass
        
        # 整数答案验证
        elif correct_ans.isdigit() and user_ans.isdigit():
            is_correct = user_ans == correct_ans
        
        # 向量/坐标答案验证(忽略空格和中英文符号)
        elif correct_ans.startswith('(') and correct_ans.endswith(')'):
            user_clean = user_ans.replace(' ', '').replace(',', ',').lower()
            correct_clean = correct_ans.replace(' ', '').replace(',', ',').lower()
            is_correct = user_clean == correct_clean
        
        # 多项式/因式分解答案验证(忽略空格和次方符号)
        elif 'x' in correct_ans:
            user_clean = user_ans.replace(' ', '').replace('^', '').lower()
            correct_clean = correct_ans.replace(' ', '').replace('^', '').lower()
            is_correct = user_clean == correct_clean
        
        # 分数答案验证
        elif '/' in correct_ans:
            is_correct = user_ans == correct_ans
        
        # 纯文本答案验证
        else:
            is_correct = user_ans == correct_ans
        
        # 生成结果反馈
        if is_correct:
            results.append(f"✅ 题目 {idx+1} 正确!")
            score += 1
        else:
            results.append(f"❌ 题目 {idx+1} 错误,正确答案:{correct_ans}")
    
    results.append(f"------------------------\n总分:{score}/{len(questions)}")
    return "\n".join(results)

# 创建Gradio界面
with gr.Blocks(title="GeoGebra数学测试题", theme=gr.themes.Soft()) as app:
    gr.Markdown("# GeoGebra数学应用能力测试")
    gr.Markdown("### 说明:非整数答案请保留五位有效数字,直接输入数字或表达式")
    
    # 动态生成题目输入框
    input_components = []
    with gr.Column():
        for idx, q in enumerate(questions):
            with gr.Row():
                gr.Markdown(f"**{idx+1}. {q}**")
                input_box = gr.Textbox(
                    label=f"题目 {idx+1} 答案",
                    placeholder="在此输入答案...",
                    container=False
                )
                input_components.append(input_box)
    
    # 提交按钮与结果显示
    gr.Markdown("---")
    with gr.Row():
        submit_btn = gr.Button("提交答案", variant="primary")
        clear_btn = gr.Button("清空答案")
    result_display = gr.Textbox(
        label="答题结果",
        lines=15,
        placeholder="提交后将在此显示每道题的对错及总分..."
    )
    
    # 绑定事件
    submit_btn.click(
        fn=verify_answers,
        inputs=input_components,
        outputs=result_display
    )
    clear_btn.click(
        fn=lambda: [""]*len(input_components),
        inputs=None,
        outputs=input_components
    )

# 启动应用
if __name__ == "__main__":
    app.launch(share=True)