1 创作目的
给熊孩子批量出计算题
2 实现的功能
可以选择计算的数字范围
可以选择出题量
内容涵盖四则运算
生成试卷和答案
数字随机生成
3 代码实现
import PySimpleGUI as sg import random from docx import Document from docx.shared import Pt def generate_arithmetic_question(max_number): operators = ['+', '-', '*', '/'] operator = random.choice(operators) if operator == '+': num1 = random.randint(1, max_number) num2 = random.randint(1, max_number) elif operator == '-': # 减法,确保结果非负 num1 = random.randint(1, max_number) num2 = random.randint(1, num1) elif operator == '*': num1 = random.randint(1, max_number) num2 = random.randint(1, max_number) elif operator == '/': # 除法,确保整除且分母不为0 num1 = random.randint(1, max_number) num2 = random.ran