国产 无码 综合区,色欲AV无码国产永久播放,无码天堂亚洲国产AV,国产日韩欧美女同一区二区

【加強版】小學數(shù)學出題,加減乘除混合運算,支持自定義數(shù)字,一鍵打印

這篇具有很好參考價值的文章主要介紹了【加強版】小學數(shù)學出題,加減乘除混合運算,支持自定義數(shù)字,一鍵打印。希望對大家有所幫助。如果存在錯誤或未考慮完全的地方,請大家不吝賜教,您也可以點擊"舉報違法"按鈕提交疑問。

【加強版】小學數(shù)學出題,加減乘除混合運算,支持自定義數(shù)字,一鍵打印,JavaScript,前端在線預(yù)覽:在線HTML代碼預(yù)覽和運行工具 - UU在線工具? ?復制下面代碼后到該地址預(yù)覽即可

?注意:在線預(yù)覽不能打印。如需打印,在電腦本地上新建文本文檔,粘貼代碼后保存,然后把文件后綴改為.html運行,出題點擊打印就可以了


新增功能:
1、支持加減乘除運算混合多選
2、支持自定義數(shù)字運算個數(shù)
3、支持自定義出題數(shù)量
4、支持一鍵打印成pdf
5、小學數(shù)學沒有負數(shù),保證結(jié)果不出現(xiàn)負數(shù)
6、出題分列展示、新增答案下劃線
7、界面美化文章來源地址http://www.zghlxwxcb.cn/news/detail-797546.html

<!DOCTYPE html>
<html lang="zh">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>小學生數(shù)學題生成器</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>小學生數(shù)學題生成器</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>
            數(shù)字個數(shù):<input type="number" id="numOfDigits" value="2" min="1" style="width: 50px;">
        </label> <br>
        <label>
            允許小數(shù):<input type="checkbox" id="allowDecimal">
        </label>
        <br>
        <label>
            數(shù)字范圍:
            <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>
            出題數(shù)量:<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>

到了這里,關(guān)于【加強版】小學數(shù)學出題,加減乘除混合運算,支持自定義數(shù)字,一鍵打印的文章就介紹完了。如果您還想了解更多內(nèi)容,請在右上角搜索TOY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!

本文來自互聯(lián)網(wǎng)用戶投稿,該文觀點僅代表作者本人,不代表本站立場。本站僅提供信息存儲空間服務(wù),不擁有所有權(quán),不承擔相關(guān)法律責任。如若轉(zhuǎn)載,請注明出處: 如若內(nèi)容造成侵權(quán)/違法違規(guī)/事實不符,請點擊違法舉報進行投訴反饋,一經(jīng)查實,立即刪除!

領(lǐng)支付寶紅包贊助服務(wù)器費用

相關(guān)文章

  • 圖像四則運算(加減乘除)

    圖像四則運算(加減乘除)

    實驗?zāi)康模?1.了解圖像的算術(shù)運算在數(shù)字圖像處理中的初步應(yīng)用。 2.體會圖像算術(shù)運算處理的過程和處理前后圖像的變化。 3.能夠?qū)崿F(xiàn)簡單的圖像處理 實驗原理: 圖像的代數(shù)運算包括加,減,乘,除,這些運算的主要對象是圖像數(shù)據(jù)塊中的數(shù)據(jù)。這四種代數(shù)運算可以由如

    2024年02月08日
    瀏覽(25)
  • C語言加減乘除運算

    加減乘除是常見的數(shù)學運算,C語言當然支持,不過,C語言中的運算符號與數(shù)學中的略有不同,請見下表。 加法 減法 乘法 除法 求余數(shù)(取余) 數(shù)學 + - × ÷ 無 C語言 + - * / % C語言中的加號、減號與數(shù)學中的一樣,乘號、除號不同;另外C語言還多了一個求余數(shù)的運算符,就是

    2024年02月06日
    瀏覽(16)
  • 只使用位運算實現(xiàn)加減乘除

    只使用位運算實現(xiàn)加減乘除

    在線OJ: LeetCode 29. 兩數(shù)相除 原題目的要求是不能使用乘法, 除法和取余運算符實現(xiàn)除法. 在本篇博客中把題目要求提高一點, 這里只使用位運算來實現(xiàn), 順便的也就把只使用位運算實現(xiàn)加減乘除實現(xiàn)了. 首先我們需要知道兩數(shù)之和可以是兩個數(shù)位相加和不進位相加之和, 而兩數(shù)進

    2024年02月06日
    瀏覽(45)
  • Rust 復數(shù)運算,重載加減乘除運算

    Rust 復數(shù)運算,重載加減乘除運算

    復數(shù)定義 由實數(shù)部分和虛數(shù)部分所組成的數(shù),形如a+bi 。 其中a、b為實數(shù),i 為“虛數(shù)單位”,i2 = -1,即虛數(shù)單位的平方等于-1。 a、b分別叫做復數(shù)a+bi的實部和虛部。 當b=0時,a+bi=a 為實數(shù); 當b≠0時,a+bi 又稱虛數(shù); 當b≠0、a=0時,bi 稱為純虛數(shù)。 實數(shù)和虛數(shù)都是復

    2024年02月13日
    瀏覽(20)
  • Python Opencv實踐 - 圖像的加減乘除

    Python Opencv實踐 - 圖像的加減乘除

    ? ? ? ? ? ?

    2024年02月13日
    瀏覽(25)
  • Pytorch入門:Tensor加減乘除矩陣運算

    若張量維數(shù)大于2,則對最后兩維進行matmul。進行此運算的要求是張量a與b除最后兩維外的其他維必須一致:

    2024年02月12日
    瀏覽(25)
  • Java進行數(shù)字計算 BigDecimal計算(加減乘除)

    Double只能處理16位有效數(shù)精度,在某些情況下精度對其需求是不夠的,所以就有了BigDecimal。因為BigDecimal的精度范圍的范圍大,所以在問我們的開發(fā)業(yè)務(wù)中對精度要求高的屬性,就需要BigDecimal來進行存儲計算,防止精度丟失。這里我主要介紹一下BigDecimal的加,減,乘,除。四

    2023年04月08日
    瀏覽(22)
  • 【python&flask-1】簡單實現(xiàn)加減乘除輸入界面

    【python&flask-1】簡單實現(xiàn)加減乘除輸入界面

    app.py index.html result.html 支持小數(shù)點計算

    2024年02月09日
    瀏覽(17)
  • 用Vue的三種方法實現(xiàn)加減乘除運算

    用Vue的三種方法實現(xiàn)加減乘除運算

    js插件:vue.js 教程: 首先在工具內(nèi)引入vue.js 然后在body里面創(chuàng)建一個div并設(shè)置id,我這里給id命名為\\\"app\\\" 在id命名為\\\"app\\\"的div內(nèi)使用input標簽和select標簽來設(shè)置運算框 然后用 methods方法?computed方法?watch(偵聽器)方法 做出3種不同的加減乘除運算 第一種computed方法: 接下來我們在

    2024年02月09日
    瀏覽(40)

覺得文章有用就打賞一下文章作者

支付寶掃一掃打賞

博客贊助

微信掃一掃打賞

請作者喝杯咖啡吧~博客贊助

支付寶掃一掃領(lǐng)取紅包,優(yōu)惠每天領(lǐng)

二維碼1

領(lǐng)取紅包

二維碼2

領(lǐng)紅包