{"id":156,"date":"2026-06-29T09:25:31","date_gmt":"2026-06-29T09:25:31","guid":{"rendered":"https:\/\/dyson-fereday.ovh\/cs\/?p=156"},"modified":"2026-06-29T09:47:56","modified_gmt":"2026-06-29T09:47:56","slug":"term-3-1-basic-python-code","status":"publish","type":"post","link":"https:\/\/dyson-fereday.ovh\/cs\/term-3-1-basic-python-code\/","title":{"rendered":"Term 3.1 Basic Python Code\u00a0"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\">For the next term we are going to work on programming with Python. The version we use at school can be <a href=\"https:\/\/www.python.org\/downloads\/release\/python-343\/\" target=\"_blank\" rel=\"noreferrer noopener\">freely downloaded here\u202f<\/a>&nbsp;<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><a href=\"https:\/\/youtu.be\/C9YqasWbkNU\" target=\"_blank\" rel=\"noreferrer noopener\">Introducing Python and basic maths functions<\/a>&nbsp;<\/p>\n\n\n\n<figure class=\"wp-block-embed is-type-video is-provider-youtube wp-block-embed-youtube wp-embed-aspect-16-9 wp-has-aspect-ratio\"><div class=\"wp-block-embed__wrapper\">\n<iframe loading=\"lazy\" title=\"Introducing Python and basic maths functions\" width=\"1290\" height=\"726\" src=\"https:\/\/www.youtube.com\/embed\/C9YqasWbkNU?feature=oembed\" frameborder=\"0\" allow=\"accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share\" referrerpolicy=\"strict-origin-when-cross-origin\" allowfullscreen><\/iframe>\n<\/div><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">To start with&nbsp;lets&nbsp;get to grips with the basic operations on Python:&nbsp;<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Mathematical operations in Python are expressed like this:&nbsp;<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Addition +&nbsp;<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Subtraction &#8211;&nbsp;<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Multiplication *&nbsp;<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Division \/&nbsp;<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Let&#8217;s try using the first window on IDLE to see what happens when we type these equations one at a time:&nbsp;<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>300+400<\/strong>&nbsp;<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>987-653<\/strong>&nbsp;<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>12*9<\/strong>&nbsp;<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>30\/6<\/strong>&nbsp;<\/p>\n\n\n\n<div class=\"wp-python-runner\" style=\"border: 1px solid #ccc; padding: 15px; border-radius: 5px; background-color: #f9f9f9; max-width: 550px; margin: 20px auto; font-family: sans-serif;\">\n    <h3 style=\"margin-top: 0;\">Try Your Own Python Math<\/h3>\n    <p style=\"font-size: 14px; color: #555;\">Change the numbers below (e.g., use <code>*<\/code> to multiply, <code>\/<\/code> to divide) and click Run!<\/p>\n    \n    <textarea id=\"wp-python-code\" rows=\"6\" style=\"width: 100%; font-family: monospace; font-size: 14px; padding: 10px; border: 1px solid #ddd; border-radius: 4px; box-sizing: border-box;\"># Try changing these numbers, or try 50 * 2\nprint(300 + 400)<\/textarea>\n    \n    <button id=\"wp-python-btn\" onclick=\"triggerPython()\" style=\"margin-top: 10px; padding: 10px 20px; background-color: #0073aa; color: white; border: none; border-radius: 4px; cursor: pointer; font-weight: bold;\">Run Code<\/button>\n\n    <h4 style=\"margin-bottom: 5px; margin-top: 15px;\">Output:<\/h4>\n    <pre id=\"wp-python-output\" style=\"background-color: #222; color: #fff; padding: 10px; border-radius: 4px; font-family: monospace; font-size: 14px; overflow-x: auto; white-space: pre-wrap; margin: 0;\">Click 'Run Code' to start...<\/pre>\n<\/div>\n\n<script>\n    \/\/ DEFENSIVE SANDBOX MOCKING\n    \/\/ We wrap this in a global check before anything else executes\n    (function() {\n        function createMockStorage() {\n            return {\n                _data: {},\n                setItem: function(id, val) { this._data[id] = String(val); },\n                getItem: function(id) { return this._data.hasOwnProperty(id) ? this._data[id] : null; },\n                removeItem: function(id) { delete this._data[id]; },\n                clear: function() { this._data = {}; },\n                length: 0\n            };\n        }\n\n        \/\/ Catch and mock sessionStorage\n        try {\n            var val = window.sessionStorage;\n        } catch (e) {\n            try {\n                Object.defineProperty(window, 'sessionStorage', { value: createMockStorage(), configurable: true });\n            } catch (err) {\n                window.sessionStorage = createMockStorage();\n            }\n        }\n\n        \/\/ Catch and mock localStorage (Pyodide checks both)\n        try {\n            var val2 = window.localStorage;\n        } catch (e) {\n            try {\n                Object.defineProperty(window, 'localStorage', { value: createMockStorage(), configurable: true });\n            } catch (err) {\n                window.localStorage = createMockStorage();\n            }\n        }\n    })();\n\n    let pyodideInstance = null;\n    let isScriptLoading = false;\n\n    function loadPyodideScript() {\n        return new Promise((resolve, reject) => {\n            if (typeof window.loadPyodide === 'function') return resolve();\n            \n            if (isScriptLoading) {\n                let checkInterval = setInterval(() => {\n                    if (typeof window.loadPyodide === 'function') {\n                        clearInterval(checkInterval);\n                        resolve();\n                    }\n                }, 50);\n                return;\n            }\n            \n            isScriptLoading = true;\n            const script = document.createElement('script');\n            script.src = \"https:\/\/cdn.jsdelivr.net\/pyodide\/v0.26.1\/full\/pyodide.js\";\n            \n            script.onload = () => {\n                let verifyInterval = setInterval(() => {\n                    if (typeof window.loadPyodide === 'function') {\n                        clearInterval(verifyInterval);\n                        resolve();\n                    }\n                }, 30);\n            };\n            \n            script.onerror = () => reject(new Error(\"Failed to load Python script file from CDN.\"));\n            document.head.appendChild(script);\n        });\n    }\n\n    async function triggerPython() {\n        const outputBox = document.getElementById('wp-python-output');\n        const runButton = document.getElementById('wp-python-btn');\n        const code = document.getElementById('wp-python-code').value;\n\n        if (!pyodideInstance) {\n            outputBox.innerText = \"Downloading Python engine (First run takes 2-4s)...\";\n            runButton.disabled = true;\n            \n            try {\n                await loadPyodideScript();\n                outputBox.innerText = \"Initializing Python environment...\";\n                \n                pyodideInstance = await window.loadPyodide({\n                    indexURL: \"https:\/\/cdn.jsdelivr.net\/pyodide\/v0.26.1\/full\/\"\n                });\n                \n            } catch (err) {\n                outputBox.innerText = \"Error loading Python: \" + err.message;\n                runButton.disabled = false;\n                return;\n            }\n            runButton.disabled = false;\n        }\n\n        outputBox.innerText = \"Running...\";\n        try {\n            pyodideInstance.runPython(`\n                import sys\n                import io\n                sys.stdout = io.StringIO()\n            `);\n            \n            await pyodideInstance.runPythonAsync(code);\n            const output = pyodideInstance.runPython(\"sys.stdout.getvalue()\");\n            outputBox.innerText = output || \"Executed successfully with no output.\";\n        } catch (err) {\n            outputBox.innerText = err.message;\n        }\n    }\n<\/script>\n\n\n\n<p class=\"wp-block-paragraph\"><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Now let&#8217;s try this all again on your computer using IDLE:<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>To start with you need to search for and open IDLE:&nbsp;<\/strong><\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"399\" height=\"76\" src=\"https:\/\/dyson-fereday.ovh\/cs\/wp-content\/uploads\/2026\/06\/image-68.png\" alt=\"\" class=\"wp-image-163\" srcset=\"https:\/\/dyson-fereday.ovh\/cs\/wp-content\/uploads\/2026\/06\/image-68.png 399w, https:\/\/dyson-fereday.ovh\/cs\/wp-content\/uploads\/2026\/06\/image-68-300x57.png 300w\" sizes=\"auto, (max-width: 399px) 100vw, 399px\" \/><\/figure>\n\n\n\n<figure class=\"wp-block-image\"><img decoding=\"async\" src=\"https:\/\/euc-onenote.officeapps.live.com\/o\/GetImage.ashx?&amp;WOPIsrc=https%3A%2F%2Fstgeorgeslu%2Esharepoint%2Ecom%2Fsites%2FY4DigitalApps%2D2023%2D24%2F%5Fvti%5Fbin%2Fwopi%2Eashx%2Ffiles%2F1ec1a010f1e5409595eb2693ebabbfa9&amp;access_token=eyJhbGciOiJSUzI1NiIsImtpZCI6IkFFRDVEQUYzOThFODI5M0I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xMSIsIm5iZiI6IjE3ODI3MjQwNTkiLCJleHAiOiIxNzgyNzYwMDU5In0%2EjS9DTYOqvOrA5YCIg%5FamMeQ6JiIdy8W0XRliZuf%2DC1nUF3j0%5FofKjkOmbj4HZjexzsiDytL8eTVY2QpiHBkV32NZj6NpOtMhBUn8UwnEFMczU5X8sknkQFNyn9ML9LKVZzpefHRhTzVEJ9xDMVa5d2FY8%2DLCMvJF4CajlxzpnWkV6o1HljydAGvaAkHdqzP0ouYviHTuPzllqvw4bxNxUCyxkggHXk8TI76YvkN16fMIt1nzrg2ze91AotFzsXMM29BPXm9KjGVJwmzGkEofmQAhkgfOCpgjej7ZU%2DAd3xA2XXEH1h3FVFX4sC6UX%2DfPN6XM7odeKX0p0xw5uv1McA&amp;access_token_ttl=1782760059947&amp;ObjectDataBlobId=%7Be422b0b1-da5b-0f08-04a7-0d48887ba044%7D%7B1%7D&amp;usid=42529185-7e0d-403b-886c-07768561f9c6&amp;build=16.0.20218.41022&amp;waccluster=GEU7&amp;wdwacuseragent=MSWACONSync\" alt=\"File \nIDLE Shell 3.12.2 \nEdit Shell Debug Options Window Hel \nPython 3 .12. 2 (tags\/v3 . 12.2:6abd \non Win32 \nType &quot;help&quot; \n&quot; copy ghC &quot; \n&quot; credi \n300+400 \n700 \"\/><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">Hopefully you saw that you could use Python to solve a basic mathematical equation for you.&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>For the next term we are going to work on programming with Python. The version we use at school can be freely downloaded here\u202f&nbsp; Introducing Python and basic maths functions&nbsp; To start with&nbsp;lets&nbsp;get to grips with the basic operations on Python:&nbsp; Mathematical operations in Python are expressed like this:&nbsp; Addition +&nbsp; Subtraction &#8211;&nbsp; Multiplication *&nbsp; [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[9],"tags":[],"class_list":["post-156","post","type-post","status-publish","format-standard","hentry","category-year6"],"blocksy_meta":[],"_links":{"self":[{"href":"https:\/\/dyson-fereday.ovh\/cs\/wp-json\/wp\/v2\/posts\/156","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/dyson-fereday.ovh\/cs\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/dyson-fereday.ovh\/cs\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/dyson-fereday.ovh\/cs\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/dyson-fereday.ovh\/cs\/wp-json\/wp\/v2\/comments?post=156"}],"version-history":[{"count":7,"href":"https:\/\/dyson-fereday.ovh\/cs\/wp-json\/wp\/v2\/posts\/156\/revisions"}],"predecessor-version":[{"id":171,"href":"https:\/\/dyson-fereday.ovh\/cs\/wp-json\/wp\/v2\/posts\/156\/revisions\/171"}],"wp:attachment":[{"href":"https:\/\/dyson-fereday.ovh\/cs\/wp-json\/wp\/v2\/media?parent=156"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/dyson-fereday.ovh\/cs\/wp-json\/wp\/v2\/categories?post=156"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/dyson-fereday.ovh\/cs\/wp-json\/wp\/v2\/tags?post=156"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}