【加强版】小学数学出题,加减乘除混合运算,支持自定义数字,一键打印

在线预览:在线HTML代码预览和运行工具 - UU在线工具   复制下面代码后到该地址预览即可

 注意:在线预览不能打印。如需打印,在电脑本地上新建文本文档,粘贴代码后保存,然后把文件后缀改为.html运行,出题点击打印就可以了


新增功能:
1、支持加减乘除运算混合多选
2、支持自定义数字运算个数
3、支持自定义出题数量
4、支持一键打印成pdf
5、小学数学没有负数,保证结果不出现负数
6、出题分列展示、新增答案下划线
7、界面美化

<!DOCTYPE html>
<html lang="zh">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>小学生数学题生成器</title>
    <style>
        body {
            font-family: Arial, sans-serif;
            background-color: #f4f4f4;
            margin: 0;
            display: block;
            flex-direction: column;
            align-items: center;
            justify-content: center;
        }
        #options {
            display: block;
            margin: 20px auto;
            background-color: #fff;
            border-radius: 5px;
            box-shadow: 0 2px 5px rgba(0, 0, 0, 0.1);
            padding: 20px;
            box-sizing: border-box;
            width: 500px;
			line-height: 35px;
        }

        label {
            margin-right: 10px;
            margin-bottom: 10px;
            font-size: 16px;
        }

        button {
    padding: 5px;
    background-color: #4caf50;
    color: #fff;
    border: none;
    border-radius: 5px;
    cursor: pointer;
        }

        #questions {
            display: flex;
            flex-wrap: wrap;
            justify-content: space-between;
            margin-top: 20px;
        }

        .question {
            width: 48%;
            box-sizing: border-box;
            padding: 10px;
            background-color: #fff;
            border-radius: 5px;
            box-shadow: 0 2px 5px rgba(0, 0, 0, 0.1);
            margin-bottom: 10px;
            font-size: 18px;
        }

        .answer {
            display: none;
            font-size: 16px;
        }

        #printHeader {
            display: none;
            margin-bottom: 20px;
        }

        @media print {
            #printHeader {
                display: block;
                text-align: center;
                margin-bottom: 30px; 
            }

            body {
                margin: 30px; 
            }

            .column {
                display: inline-block;
                width: 48%;
                box-sizing: border-box;
                margin-bottom: 20px;
                break-before: auto; 
            }

            .question {
                page-break-inside: avoid; 
            }

            @page {
                size: A4;
                margin: 25mm 10mm 25mm 10mm;
            }

            .question:nth-child(n+21) {
                display: none;
            }
        }
		div#printHeader {
    text-align: center;
    margin-bottom: 15px;
}
    </style>
</head>
<body>
    <div class="hd1" style="text-align:center;font-size:35px;background-color: #4CAF50;min-height: 100px;padding-top: 50px;"><font>小学生数学题生成器</font></div>
    <div id="options">运算符号:
        <label>
            <input type="checkbox" id="additionCheckbox" checked="checked"> 加法
        </label>
        <label>
            <input type="checkbox" id="subtractionCheckbox"> 减法
        </label>
        <label>
            <input type="checkbox" id="multiplicationCheckbox"> 乘法
        </label>
        <label>
            <input type="checkbox" id="divisionCheckbox"> 除法
        </label>
        <br>
        <label>
            数字个数:<input type="number" id="numOfDigits" value="2" min="1" style="width: 50px;">
        </label> <br>
        <label>
            允许小数:<input type="checkbox" id="allowDecimal">
        </label>
        <br>
        <label>
            数字范围:
            <label><input type="number" id="minRange" value="1" min="1" style="width: 50px;"></label>-
            <label><input type="number" id="maxRange" value="100" min="1" style="width: 50px;"></label>
        </label>
        <br>
        <label>
            出题数量:<input type="number" id="numOfQuestions" value="30" min="1" style="width: 50px;">
        </label>
        <br>
        <button onclick="generateQuestions()">生成题目</button>
        <button onclick="printQuestions()">一键打印</button>
        <button onclick="toggleAnswers()">显示/隐藏答案</button>
    </div>

    <div id="questions"></div>

    <script>

		function generateQuestions() {
            const addition = document.getElementById("additionCheckbox").checked;
            const subtraction = document.getElementById("subtractionCheckbox").checked;
            const multiplication = document.getElementById("multiplicationCheckbox").checked;
            const division = document.getElementById("divisionCheckbox").checked;
            const numOfDigits = document.getElementById("numOfDigits").value;
            const allowDecimal = document.getElementById("allowDecimal").checked;
            const minRange = parseInt(document.getElementById("minRange").value);
            const maxRange = parseInt(document.getElementById("maxRange").value);
            const numOfQuestions = document.getElementById("numOfQuestions").value;

            const questionsContainer = document.getElementById("questions");
            questionsContainer.innerHTML = "";

            for (let i = 0; i < numOfQuestions; i++) {
                let validQuestion = false;
                let questionText, answerText;

                while (!validQuestion) {
                    const operators = getRandomOperators(addition, subtraction, multiplication, division, numOfDigits);
                    const numbers = generateNumbers(numOfDigits, allowDecimal, minRange, maxRange);
                    questionText = generateQuestionText(numbers, operators, allowDecimal);
                    answerText = calculateAnswer(numbers, operators, allowDecimal).toFixed(allowDecimal ? 2 : 0);

                    if (!containsNegativeNumber(questionText) && answerText >= 0) {
                        validQuestion = true;
                    }
                }

                const questionDiv = document.createElement("div");
                questionDiv.classList.add("question");

                questionDiv.innerHTML = `<span>${questionText}</span><span class="answer">${parseFloat(answerText)}</.toFixed(2)}</span>`;
                questionsContainer.appendChild(questionDiv);
            }
        }

        function getRandomOperators(addition, subtraction, multiplication, division, numOfDigits) {
            const availableOperators = [];
            if (addition) availableOperators.push('+');
            if (subtraction) availableOperators.push('-');
            if (multiplication && numOfDigits >= 2) availableOperators.push('*');
            if (division && numOfDigits >= 2) availableOperators.push('/');

            const selectedOperators = [];
            for (let i = 0; i < numOfDigits - 1; i++) {
                const randomOperator = availableOperators[Math.floor(Math.random() * availableOperators.length)];
                selectedOperators.push(randomOperator);
            }

            return selectedOperators;
        }

        function generateQuestionText(numbers, operators, allowDecimal) {
            let questionText = numbers[0].toString();
            for (let i = 0; i < operators.length; i++) {
                const operator = operators[i];
                const num = allowDecimal ? parseFloat(numbers[i + 1]).toFixed(2) : parseInt(numbers[i + 1]);
                questionText += ` ${operator.replace('*', 'x').replace('/', '÷')} ${num}`;
            }
            questionText += ' =';

            return questionText;
        }

        function generateNumbers(numOfDigits, allowDecimal, minRange, maxRange) {
            const randomNumber = () => allowDecimal 
                ? (Math.random() * (maxRange - minRange) + minRange).toFixed(2)
                : Math.floor(Math.random() * (maxRange - minRange + 1)) + minRange;

            const numbers = [];
            for (let i = 0; i < numOfDigits; i++) {
                numbers.push(randomNumber());
            }
            return numbers;
        }

        function calculateAnswer(numbers, operators, allowDecimal) {
            const calculateMulDiv = (nums, ops) => {
                for (let i = 0; i < ops.length; i++) {
                    if (ops[i] === '*' || ops[i] === '/') {
                        const result = ops[i] === '*' ? nums[i] * nums[i + 1] : nums[i] / nums[i + 1];
                        nums.splice(i, 2, result);
                        ops.splice(i, 1);
                        i--;
                    }
                }
            };

            const nums = numbers.map(num => parseFloat(num));
            const ops = operators.map(op => op);

            calculateMulDiv(nums, ops);

            let result = nums[0];
            for (let i = 0; i < ops.length; i++) {
                const num = nums[i + 1];
                const operator = ops[i];

                switch (operator) {
                    case '+':
                        result += num;
                        break;
                    case '-':
                        result -= num;
                        break;
                    default:
                        break;
                }
            }

            return allowDecimal
                ? parseFloat(result.toFixed(2))
                : parseInt(result);
        }

        function containsNegativeNumber(questionText) {
            const parts = questionText.split(' ');
            for (let i = 0; i < parts.length; i++) {
                if (parseFloat(parts[i]) < 0) {
                    return true;
                }
            }
            return false;
        }

        function printQuestions() {
            const printWindow = window.open('', '_blank');
            const printContent = document.getElementById("questions").innerHTML;

            printWindow.document.write(`
                <html lang="zh">
                <head>
                    <meta charset="UTF-8">
                    <meta name="viewport" content="width=device-width, initial-scale=1.0">
                    <title>打印题目</title>
                    <style>
                        body {
                            font-family: Arial, sans-serif;
                            margin: 30px; 
                        }

                        .column {
                            display: inline-block;
                            width: 48%;
                            box-sizing: border-box;
                            margin-bottom: 20px;
                        }

                        .question {
                            padding: 10px;
                            background-color: #fff;
                            border-radius: 5px;
                            box-shadow: 0 2px 5px rgba(0, 0, 0, 0.1);
                            margin-bottom: 10px;
                            font-size: 18px;
                        }

                        .answer {
                            display: none;
                            font-size: 16px;
                        }
                    </style>
                </head>
                <body>
                    <div id="printHeader" style="text-align: center;margin-bottom: 20px;">
                        <div>姓名:_________ 日期:____月____日 时间:________ 答对:_______题</div>
                    </div>
                    <div class="column" id="column1"></div>
                    <div class="column" id="column2"></div>
                </body>
                </html>
            `);

            const column1 = printWindow.document.getElementById("column1");
            const column2 = printWindow.document.getElementById("column2");
            const questions = document.querySelectorAll('.question');

            let countColumn1 = 0;
            let countColumn2 = 0;

            questions.forEach((question, index) => {
                const column = index % 2 === 0 ? column1 : column2;
                const clonedQuestion = question.cloneNode(true);

                // Replace answer content with formatted answer
                const answerElement = clonedQuestion.querySelector('.answer');
                const answerText = answerElement.textContent;
                answerElement.textContent = parseFloat(answerText).toFixed(2);

                column.appendChild(clonedQuestion);

                if (index % 2 === 0) {
                    countColumn1++;
                } else {
                    countColumn2++;
                }
            });

            printWindow.document.close();
            printWindow.print();
        }

        function toggleAnswers() {
            const answers = document.querySelectorAll('.answer');
            answers.forEach(answer => {
                answer.style.display = (answer.style.display === 'none' || answer.style.display === '') ? 'inline' : 'none';
            });
        }
		
		
    </script>
</body>
</html>

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mfbz.cn/a/328645.html

如若内容造成侵权/违法违规/事实不符,请联系我们进行投诉反馈qq邮箱809451989@qq.com,一经查实,立即删除!

相关文章

【Java JVM】栈帧

执行引擎是 Java 虚拟机核心的组成部分之一。 在《Java虚拟机规范》中制定了 Java 虚拟机字节码执行引擎的概念模型, 这个概念模型成为各大发行商的 Java 虚拟机执行引擎的统一外观 (Facade)。 不同的虚拟机的实现中, 通常会有 解释执行 (通过解释器执行)编译执行 (通过即时编…

rust跟我学二:模块编写与使用

图为RUST吉祥物 大家好,我是get_local_info作者带剑书生,这里用一篇文章讲解get_local_info中模块的使用。 首先,先要了解get_local_info是什么? get_local_info是一个获取linux系统信息的rust三方库,并提供一些常用功能,目前版本0.2.4。详细介绍地址:[我的Rust库更新]g…

【物联网】物联网设备和应用程序涉及协议的概述

物联网设备和应用程序涉及协议的概述。帮助澄清IoT层技术栈和头对头比较。 物联网涵盖了广泛的行业和用例&#xff0c;从单一受限制的设备扩展到大量跨平台部署嵌入式技术和实时连接的云系统。 将它们捆绑在一起是许多传统和新兴的通信协议&#xff0c;允许设备和服务器以新的…

小程序样例1:简单待办列表

基本功能&#xff1a; 显示所有待办列表&#xff08;点击不同的文本进行显示&#xff09; 没完成的待办 已完成的待办 新建待办test 清除待办foo 代码js文件&#xff1a; //index.js //获取应用实例 const app getApp(); Page({data: {todo: ,todos: [{"id": 1474…

鸿蒙Harmony-列表组件(List)详解

不要和别人比生活&#xff0c;每个人阶段不同&#xff0c;追求不同&#xff0c;活法自然也不同。只要今天的你能比昨天的你快乐一点点&#xff0c;那你就是自己人生赢家。 目录 一&#xff0c;定义 二&#xff0c;布局与约束 2.1 布局 2.2 约束 三&#xff0c;开发布局 3.1 设置…

LabVIEW模拟荧光显微管滑动实验

LabVIEW模拟荧光显微管滑动实验 在现代生物医学研究中&#xff0c;对微观生物过程的精准模拟和观察至关重要。本案例展示了如何利用LabVIEW软件和专业硬件平台&#xff0c;创新地模拟荧光显微管在滑动实验中的动态行为&#xff0c;这一过程不仅提升了实验效率&#xff0c;还为…

探寻爬虫世界01:HTML页面结构

文章目录 一、引言&#xff08;一&#xff09;背景介绍&#xff1a;选择爬取51job网站数据的原因&#xff08;二&#xff09;目标与需求明确&#xff1a;爬取51job网站数据的目的与用户需求 二、网页结构探索&#xff08;一&#xff09;51job网页结构分析1、页面组成&#xff1…

速通——决策树(泰坦尼克号乘客生存预测案例)

一、决策树 1、概述 树中每个内部节点表示一个特征上的判断&#xff0c;每个分支代表一个判断结果的输出&#xff0c;每个叶子节点代表一种分类结果 2、建立过程 1. 特征选择&#xff1a;选取有较强分类能力的特征。 2. 决策树生成&#xff1a;根据选择的特征生成决策树。 3.…

下一代 Vue3 Devtools 正式开源

什么是 Vue DevTools Vue DevTools 是一个旨在增强 Vue 开发人员体验的工具,它提供了一些功能来帮助开发者更好地了解 Vue 应用程序。 Vue DevTools:Unleash Vue Developer Experience. Enhance your Vue development journey with an amazing experience! 典型的功能特征包…

6.3.3分离音频和视频

6.3.3分离音频和视频 Camtasia4有一个很实用的功能&#xff0c;那就是能够把视频片段中的视频和音频分离开来&#xff0c;这在多媒体作品创作中非常有用。 1&#xff0e;启动Camtasia音频编辑器。 2&#xff0e;选择【文件】|【打开】命令&#xff0c;在弹出的“打开文件”对…

法国追梦 SAM5504/5704/5716/5808 芯片/开发板/方案 详细资料

追梦音频DSP芯片&#xff1a;可用于电子鼓、电子琴、电吉他、效果器、均衡器、啸叫抑制器等电声产品领域 一.系列芯片&#xff1a;SAM2695 SAM5708B SAM5704B SAM5504B SAM5808B SAM5716B SAM5916B 二.开发套件 1.开发板/评估板&#xff1a;2695-EK&#xff0c;5504-EK&#…

Kali Linux保姆级教程|零基础从入门到精通,看完这一篇就够了!(附工具包)

作为一名从事网络安全的技术人员&#xff0c;不懂Kali Linux的话&#xff0c;连脚本小子都算不上。 Kali Linux预装了数百种享誉盛名的渗透工具&#xff0c;使你可以更轻松地测试、破解以及进行与数字取证相关的任何其他工作。 今天给大家分享一套Kali Linux资料合集&#xf…

考研机试题收获——高精度进制转换

代码的第一遍真的很重要&#xff0c;在第一次打的时候尽量把问题思考全面&#xff0c;不要漏打少打&#xff0c;尽量不要留bug给之后de。 一、基础方面 一、处理输出的结束问题 scanf和cin默认都不会读取空格 ①scanf()&#xff1a;如果从文件中读取数据&#xff0c;当scanf()…

计算机三级(网络技术)——应用题

第一题 61.输出端口S0 &#xff08;直接连接&#xff09; RG的输出端口S0与RE的S1接口直接相连构成一个互联网段 对172.0.147.194和172.0.147.193 进行聚合 前三段相同&#xff0c;将第四段分别转换成二进制 11000001 11000010 前6位相同&#xff0c;加上前面三段 共30…

Vue3 + Electron框架读取程序外部配置文件

网上找了一堆都不行&#xff0c;根据这个步骤来肯定能用 1. 在项目下新建一个config.json文件 2. json文件中写入一些配置 3. vue.config.js中配置打包时把config.json文件copy到应用目录下 pluginOptions:{electronBuilder:{nodeIntegration:true,builderOptions: {extraReso…

VUE好看的个人博客源码

文章目录 1.设计来源1.1 首页界面1.2 我的日记界面1.3 我的文章界面1.3.1 文章列表1.3.2 文章时间轴1.3.3 文章详细 1.4 我的相册界面1.5 我的源码界面1.6 认识我界面 2.效果和源码2.1 动态效果2.2 源码目录结构 源码下载 作者&#xff1a;xcLeigh 文章地址&#xff1a;https:/…

在 Windows 11 上通过 Autoawq 启动 Mixtral 8*7B 大语言模型

在 Windows 11 上通过 Autoawq 启动 Mixtral 8*7B 大语言模型 0. 背景1. 安装依赖2. 开发 main.py3. 运行 main.py 0. 背景 看了一些文章之后&#xff0c;今天尝试在 Windows 11 上通过 Autoawq 启动 Mixtral 8*7B 大语言模型。 1. 安装依赖 pip install torch torchvision …

【Git】任何位置查看git日志

需求 现需要查看指定项目中的某个文件的 Git 日志。如有 项目代码 jflowable &#xff0c;需要查看其下文件 D:\z_workspace\jflowable\src\main\java\com\xzbd\jflowable\controller\TestController.java 的日志。 分析 一般的思路是&#xff0c;进入 jflowable 项目&#…

bledner快捷键记录

shiftc游标归到世界的中心 shifta快速添加物体 x键删除物体 r旋转物体 s是放大放小 ~查看视图 工作区&#xff1a;添加材质节点的 鼠标的滚轮&#xff1a;是旋转视图 按住 滚轮中键shift 平移视图 g键 移动 调整的时候按住shift鼠标拖动 这个时候可以比较精细的调整物体的大小…

专业140+总410+哈尔滨工业大学803信号与系统和数字逻辑电路考研经验哈工大电子信息(信息与通信工程-信通)

一年的努力付出终于有了收获&#xff0c;今年专业课140&#xff0c;总分410顺利上岸哈工大803电子信息&#xff08;信息与通信-信通&#xff09;&#xff0c;回顾总结了自己这一年的复习&#xff0c;有得有失&#xff0c;希望对大家复习有所帮助。 数学 时间安排&#xff1a;…
最新文章