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

在线预览:在线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 answerconst 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.hqwc.cn/news/417644.html

如若内容造成侵权/违法违规/事实不符,请联系编程知识网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

力扣刷MySQL-第六弹(详细讲解)

&#x1f389;欢迎您来到我的MySQL基础复习专栏 ☆* o(≧▽≦)o *☆哈喽~我是小小恶斯法克&#x1f379; ✨博客主页&#xff1a;小小恶斯法克的博客 &#x1f388;该系列文章专栏&#xff1a;力扣刷题讲解-MySQL &#x1f379;文章作者技术和水平很有限&#xff0c;如果文中出…

单页面vite打包学习

前端工程化本人真的很发怵&#xff0c;一直也没有专心去突破一下&#xff0c;都是能用就用&#xff0c;所以今天小小学习一下打包&#xff0c;先从单页面应用的vite打包开始。本文主要是一些我的大白话和有限的经验&#xff0c;如有问题望指正。 一、问题 网页要从服务器请求…

Crow:实现点击下载功能

Crow:设置网站的index.html-CSDN博客 讲述了如何完成一个最简单的网页的路由 很多网页提供了下载功能,怎么实现呢,其实也很简单。 假设网页的目录结构如图 $ tree static static ├── img │ └── goodday.jpg └── index.html //index.html <html> <body&…

近期学习文章

DNSlog在渗透测试中的实战技巧 - 网安隐藏源IP&#xff0c;提高溯源难度的几种方案 - 网安FreeBuf网络安全行业门户 【漏洞公告】某平台一个有意思的CSRF // SecTrain安全博客 浅谈Web源码泄漏-安全客 - 安全资讯平台 红队-C2 Server基础构建 - 先知社区FreeBuf网络安全行业…

力扣每日一题---1547. 切棍子的最小成本

//当我们将棍子分段之后&#xff0c;我们是不是想到了怎么组合这些棍子 //并且这些棍子有一个性质就是只能与相邻的进行组合 //暴力搜索的话复杂度很高 //在思考暴力搜索的时候&#xff0c;我们发现一个规律 //比如棍子长度1 2 1 1 2 //那么与最后一个2组合的棍子有&#xff0c…

Java毕业设计-基于ssm的网上求职招聘管理系统-第85期

获取源码资料&#xff0c;请移步从戎源码网&#xff1a;从戎源码网_专业的计算机毕业设计网站 项目介绍 基于ssm的网上求职招聘管理系统&#xff1a;前端 jsp、jquery&#xff0c;后端 springmvc、spring、mybatis&#xff0c;角色分为管理员、招聘人员、用户&#xff1b;集成…

关于大模型学习中遇到的3

来源&#xff1a;网络 Embedding模型 随着大型语言模型的发展&#xff0c;以ChatGPT为首&#xff0c;涌现了诸如ChatPDF、BingGPT、NotionAI等多种多样的应用。公众大量地将目光聚焦于生成模型的进展之快&#xff0c;却少有关注支撑许多大型语言模型应用落地的必不可少的Embed…

linux 安装nginx

介绍 官网 https://nginx.org/en/download.html 在安装nginx前首先要确认系统中安装了gcc、pcre-devel、zlib-devel、openssl-devel linux 检查是否安装过某软件包 yum -y install gcc pcre-devel zlib-devel openssl openssl-devel #下载 wget https://nginx.org/downloa…

Python实例:根据总步数计算消耗的热量值

随着人们对健康和运动的关注不断增加&#xff0c;越来越多的人开始关注自己的运动量和消耗的热量。在这个实例中&#xff0c;我们将使用Python来根据总步数计算消耗的热量值。这个实例可以帮助我们更好地理解Python中的数学计算和数据处理&#xff0c;并且让我们更清晰地了解运…

2024最新最全ChatGPT角色Prompt预设词教程

使用指南 1、可直复制使用 2、可以前往已经添加好Prompt预设的AI系统测试使用&#xff08;可自定义添加使用&#xff09; https://ai.sparkaigf.com 雅思写作考官 我希望你假定自己是雅思写作考官&#xff0c;根据雅思评判标准&#xff0c;按我给你的雅思考题和对应答案给我…

考研C语言刷编程题篇之分支循环结构基础篇(一)

目录 第一题 第二题 方法一&#xff1a;要循环两次&#xff0c;一次求阶乘&#xff0c;一次求和。 注意&#xff1a;在求和时&#xff0c;如果不将sum每次求和的初始值置为1&#xff0c;那么求和就会重复。 方法二&#xff1a; 第三题 方法一&#xff1a;用数组遍历的思想…

【设计模式-06】Observer观察者模式

简要说明 事件处理模型 场景示例&#xff1a;小朋友睡醒了哭&#xff0c;饿&#xff01; 一、v1版本(披着面向对象的外衣的面向过程) /*** description: 观察者模式-v1版本(披着面向对象的外衣的面向过程)* author: flygo* time: 2022/7/18 16:57*/ public class ObserverMain…