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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
import re
|
| 3 |
+
|
| 4 |
+
# 题目列表
|
| 5 |
+
questions = [
|
| 6 |
+
"1. 37^(-42)=",
|
| 7 |
+
"2. lim_{x→0} x³/(tanx - x)=",
|
| 8 |
+
"3. cos x = x 的实根为 x=",
|
| 9 |
+
"4. f(x)=(x-1)e^(x+1)+√(2x)+1/x-ln²x 的最小值为",
|
| 10 |
+
"5. f(x)=x/6 + sinx/x 的极值点数量为",
|
| 11 |
+
"6. y=(x-e)e^x+ln²(x+1)-√(x+1) 在(0,e1)处的切线在x轴上的截距为",
|
| 12 |
+
"7. 点(1, 0)关于直线5x-2y+3=0的对称点为",
|
| 13 |
+
"8. (2+3i)^7的虚部为",
|
| 14 |
+
"9. arg(3+7i)/(9-4i)=(弧度制)",
|
| 15 |
+
"10. 5!11! mod 998244353=",
|
| 16 |
+
"11. C₃₇¹⁵=",
|
| 17 |
+
"12. (x+2)^5除以x²+x+1的商(忽略余式)为",
|
| 18 |
+
"13. 设f(x)=x⁴e^(x²)则f^(4)(x)/e^(x²)展开后x⁴的系数为",
|
| 19 |
+
"14. 102233201和123456789的最大公约数为",
|
| 20 |
+
"15. 2025的所有因数之和为",
|
| 21 |
+
"16. ∑_{n=1}^∞ n^(-n)=",
|
| 22 |
+
"17. ∫₀¹x^(-x)dx=",
|
| 23 |
+
"18. ∑_{n=1}^{25}∏_{k=1}^n(1+1/k²)=",
|
| 24 |
+
"19. (11,45,14)×(19,198,10)=",
|
| 25 |
+
"20. 以(−2,−1,−1),(−1,1,3),(2,−4,1),(2,2,0)为顶点的四面体的体积为",
|
| 26 |
+
"21. 点(1,0)到y=arctanx的距离为",
|
| 27 |
+
"22. 5¹²+8¹²的所有质因数之和为",
|
| 28 |
+
"23. 因式分解:x⁵-6x⁴+12x³-8x²-7x-1=",
|
| 29 |
+
"24. 因式分解:a³b-3a³+a²b²+2ab²-6ab+2b³=",
|
| 30 |
+
"25. √1,√2,√3,…,√2025的方差为",
|
| 31 |
+
"26. 过(−2,−1),(−1,1),(0,2),(1,−2),(3,0)的二次曲线的离心率为",
|
| 32 |
+
"27. x³-3x-5=0的复数根的实部为",
|
| 33 |
+
"28. 已知六点(−2,−27),(−1,13),(0,5),(1,3),(2,−11),(3,−7),用最小二乘法拟合直线的相关系数为",
|
| 34 |
+
"29. 以(−1,−1),(0,5),(6,2)为顶点的三角形外接圆半径为 其垂心坐标为",
|
| 35 |
+
"30. (x+2)^4(3x²-5)(x²-6x-1)的展开式中x⁴的系数为",
|
| 36 |
+
"31. 设X~N(0,0.5²),则P(-0.2≤X≤0.3)=",
|
| 37 |
+
"32. 曲线y=2^x-x²(x∈[-2,4])的长度为",
|
| 38 |
+
"33. 椭圆x²/5+y²/2=1的周长为",
|
| 39 |
+
"34. 曲线ρ=1-sinθ在点(1,0)处的曲率为",
|
| 40 |
+
"35. 曲线2x²+y²-5y+4=0和x²+2xy-3y²-2=0的所有公切线斜率之积为",
|
| 41 |
+
"36. (13579 BD)₁₅转换为10进制是",
|
| 42 |
+
"37. f(x)=1/(1-x-x²)在x=0处的泰勒展开的前6项为",
|
| 43 |
+
"38. [2025,5202]中的质数数量为",
|
| 44 |
+
"39. 已知a₁=2,aₙ₊₁=aₙ-1/aₙ,则a₂₀₂₅=",
|
| 45 |
+
"40. 已知a₁=2,a₂=3,aₙ₊₂=aₙ₊₁-1/aₙ,则a₂₀₂₅=",
|
| 46 |
+
"41. 冰雹猜想:从27开始,迭代得到1的最少次数为",
|
| 47 |
+
"42. 已知a₁=0,a₂=1,aₙ₊₂=(n+1)(aₙ+aₙ₊₁),则a₄₀₉₆ mod 998244353=",
|
| 48 |
+
"43. 已知f²(x)f'(x)=xe^x,f(2)=3,则f(0)=",
|
| 49 |
+
"44. 已知某分子和分母均小于1000的分数约等于0.294663573085847,则该分数为",
|
| 50 |
+
"45. 满足2ⁿ中不出现重复数字的最大正整数n为",
|
| 51 |
+
"46. 已知a^a+b^b+c^c+d^d=abcd(abcd为1~9的正整数),则abcd=",
|
| 52 |
+
"47. 100! mod 998244353=",
|
| 53 |
+
"48. √(eπ)小数点后第37位是",
|
| 54 |
+
"49. 已知f''(x)=2f(x)+x,f(0)=2,f'(0)=-1/2,则f(1)=",
|
| 55 |
+
"50. 3^(4^5)的各位数字之和为"
|
| 56 |
+
]
|
| 57 |
+
|
| 58 |
+
# 答案列表(已按题目顺序整理并统一格式)
|
| 59 |
+
answers = [
|
| 60 |
+
"1.3662e-66", # 1
|
| 61 |
+
"3", # 2
|
| 62 |
+
"0.73909", # 3
|
| 63 |
+
"0.08027", # 4
|
| 64 |
+
"4", # 5
|
| 65 |
+
"-1.6762", # 6
|
| 66 |
+
"(-1.7586,1.1034)", # 7
|
| 67 |
+
"4449", # 8
|
| 68 |
+
"1.5841", # 9
|
| 69 |
+
"797038588", # 10
|
| 70 |
+
"9364199760", # 11
|
| 71 |
+
"x³+9x²+30x+41", # 12
|
| 72 |
+
"492", # 13
|
| 73 |
+
"3607", # 14
|
| 74 |
+
"3751", # 15
|
| 75 |
+
"1.2913", # 16
|
| 76 |
+
"1.2913", # 17
|
| 77 |
+
"81.672", # 18
|
| 78 |
+
"(-2322,156,1323)", # 19
|
| 79 |
+
"15.833", # 20
|
| 80 |
+
"0.67234", # 21
|
| 81 |
+
"12691", # 22
|
| 82 |
+
"(x²-3x-1)(x³-3x²+4x+1)", # 23
|
| 83 |
+
"(a²+2b)(ab-3a+b²)", # 24
|
| 84 |
+
"112.34", # 25
|
| 85 |
+
"0.84984", # 26
|
| 86 |
+
"-1.1395", # 27
|
| 87 |
+
"0.09798", # 28
|
| 88 |
+
"3.9841 (0.92308,2.8462)", # 29
|
| 89 |
+
"-475", # 30
|
| 90 |
+
"0.38117", # 31
|
| 91 |
+
"10.750", # 32
|
| 92 |
+
"11.613", # 33
|
| 93 |
+
"1.0607", # 34
|
| 94 |
+
"176", # 35
|
| 95 |
+
"13947703", # 36
|
| 96 |
+
"1+x+2x²+3x³+5x⁴+8x⁵", # 37
|
| 97 |
+
"386", # 38
|
| 98 |
+
"-35.709", # 39
|
| 99 |
+
"-125.93", # 40
|
| 100 |
+
"111", # 41
|
| 101 |
+
"641190802", # 42
|
| 102 |
+
"1.2238", # 43
|
| 103 |
+
"127/431", # 44
|
| 104 |
+
"29", # 45
|
| 105 |
+
"3435", # 46
|
| 106 |
+
"35305197", # 47
|
| 107 |
+
"3", # 48
|
| 108 |
+
"3.8564", # 49
|
| 109 |
+
"2250" # 50
|
| 110 |
+
]
|
| 111 |
+
|
| 112 |
+
def verify_answers(*user_answers):
|
| 113 |
+
"""验证用户答案并返回评分结果"""
|
| 114 |
+
results = []
|
| 115 |
+
score = 0
|
| 116 |
+
for idx, (user_ans, correct_ans) in enumerate(zip(user_answers, answers)):
|
| 117 |
+
is_correct = False
|
| 118 |
+
user_ans = str(user_ans).strip()
|
| 119 |
+
|
| 120 |
+
# 数值型答案验证(保留五位有效数字)
|
| 121 |
+
if re.match(r'^-?\d+\.\d+e?-?\d*$', correct_ans) or re.match(r'^-?\d+\.\d+$', correct_ans):
|
| 122 |
+
try:
|
| 123 |
+
# 统一科学计数法格式
|
| 124 |
+
user_num = float(user_ans.replace('×10^', 'e').replace('^', 'e'))
|
| 125 |
+
correct_num = float(correct_ans.replace('×10^', 'e').replace('^', 'e'))
|
| 126 |
+
# 计算有效数字位数
|
| 127 |
+
sig_figs = 5 - (0 if correct_num == 0 else len(str(int(abs(correct_num)))))
|
| 128 |
+
user_rounded = round(user_num, sig_figs) if sig_figs > 0 else int(round(user_num))
|
| 129 |
+
correct_rounded = round(correct_num, sig_figs) if sig_figs > 0 else int(round(correct_num))
|
| 130 |
+
is_correct = abs(user_rounded - correct_rounded) < 1e-4
|
| 131 |
+
except:
|
| 132 |
+
pass
|
| 133 |
+
|
| 134 |
+
# 整数答案验证
|
| 135 |
+
elif correct_ans.isdigit() and user_ans.isdigit():
|
| 136 |
+
is_correct = user_ans == correct_ans
|
| 137 |
+
|
| 138 |
+
# 向量/坐标答案验证(忽略空格和中英文符号)
|
| 139 |
+
elif correct_ans.startswith('(') and correct_ans.endswith(')'):
|
| 140 |
+
user_clean = user_ans.replace(' ', '').replace(',', ',').lower()
|
| 141 |
+
correct_clean = correct_ans.replace(' ', '').replace(',', ',').lower()
|
| 142 |
+
is_correct = user_clean == correct_clean
|
| 143 |
+
|
| 144 |
+
# 多项式/因式分解答案验证(忽略空格和次方符号)
|
| 145 |
+
elif 'x' in correct_ans:
|
| 146 |
+
user_clean = user_ans.replace(' ', '').replace('^', '').lower()
|
| 147 |
+
correct_clean = correct_ans.replace(' ', '').replace('^', '').lower()
|
| 148 |
+
is_correct = user_clean == correct_clean
|
| 149 |
+
|
| 150 |
+
# 分数答案验证
|
| 151 |
+
elif '/' in correct_ans:
|
| 152 |
+
is_correct = user_ans == correct_ans
|
| 153 |
+
|
| 154 |
+
# 纯文本答案验证
|
| 155 |
+
else:
|
| 156 |
+
is_correct = user_ans == correct_ans
|
| 157 |
+
|
| 158 |
+
# 生成结果反馈
|
| 159 |
+
if is_correct:
|
| 160 |
+
results.append(f"✅ 题目 {idx+1} 正确!")
|
| 161 |
+
score += 1
|
| 162 |
+
else:
|
| 163 |
+
results.append(f"❌ 题目 {idx+1} 错误,正确答案:{correct_ans}")
|
| 164 |
+
|
| 165 |
+
results.append(f"------------------------\n总分:{score}/{len(questions)}")
|
| 166 |
+
return "\n".join(results)
|
| 167 |
+
|
| 168 |
+
# 创建Gradio界面
|
| 169 |
+
with gr.Blocks(title="GeoGebra数学测试题", theme=gr.themes.Soft()) as app:
|
| 170 |
+
gr.Markdown("# GeoGebra数学应用能力测试")
|
| 171 |
+
gr.Markdown("### 说明:非整数答案请保留五位有效数字,直接输入数字或表达式")
|
| 172 |
+
|
| 173 |
+
# 动态生成题目输入框
|
| 174 |
+
input_components = []
|
| 175 |
+
with gr.Column():
|
| 176 |
+
for idx, q in enumerate(questions):
|
| 177 |
+
with gr.Row():
|
| 178 |
+
gr.Markdown(f"**{idx+1}. {q}**")
|
| 179 |
+
input_box = gr.Textbox(
|
| 180 |
+
label=f"题目 {idx+1} 答案",
|
| 181 |
+
placeholder="在此输入答案...",
|
| 182 |
+
container=False
|
| 183 |
+
)
|
| 184 |
+
input_components.append(input_box)
|
| 185 |
+
|
| 186 |
+
# 提交按钮与结果显示
|
| 187 |
+
gr.Markdown("---")
|
| 188 |
+
with gr.Row():
|
| 189 |
+
submit_btn = gr.Button("提交答案", variant="primary")
|
| 190 |
+
clear_btn = gr.Button("清空答案")
|
| 191 |
+
result_display = gr.Textbox(
|
| 192 |
+
label="答题结果",
|
| 193 |
+
lines=15,
|
| 194 |
+
placeholder="提交后将在此显示每道题的对错及总分..."
|
| 195 |
+
)
|
| 196 |
+
|
| 197 |
+
# 绑定事件
|
| 198 |
+
submit_btn.click(
|
| 199 |
+
fn=verify_answers,
|
| 200 |
+
inputs=input_components,
|
| 201 |
+
outputs=result_display
|
| 202 |
+
)
|
| 203 |
+
clear_btn.click(
|
| 204 |
+
fn=lambda: [""]*len(input_components),
|
| 205 |
+
inputs=None,
|
| 206 |
+
outputs=input_components
|
| 207 |
+
)
|
| 208 |
+
|
| 209 |
+
# 启动应用
|
| 210 |
+
if __name__ == "__main__":
|
| 211 |
+
app.launch()
|