@@ -39,13 +42,13 @@
Compose your code here
- print(team)
+ for person in team:
- for person in team:
+ print(team)
diff --git a/textbook/parsons-assets/parsons-problems/js/parsons.js b/textbook/parsons-assets/parsons-problems/js/parsons.js
index 07c574b..c7e6698 100644
--- a/textbook/parsons-assets/parsons-problems/js/parsons.js
+++ b/textbook/parsons-assets/parsons-problems/js/parsons.js
@@ -153,6 +153,16 @@ async function runPyodide(codeLines, pyodidePromise) {
}
}
+async function runPyodideSetup(pyodidePromise) {
+ // Runs any setup code that should be executed in global scope, before the solution is executed
+ let setupCode = document.querySelector("#setup-code");
+
+ if (setupCode){
+ let pyodide = await pyodidePromise;
+ await pyodide.runPython(setupCode.textContent);
+ }
+}
+
function handlePyException(excProxy) {
// Handles a dict returned from the Python reformat_exception function
function extractLineNo(tbArray) {
@@ -268,15 +278,17 @@ window.addEventListener("DOMContentLoaded", async () => {
// button to trigger code execution
const button = document.querySelector(".parsons-submit");
- button.addEventListener("click", (event) => {
+ button.addEventListener("click", async (event) => {
// clear output area before running new code
clearOutput();
let codeToRun = parseParsonsCode();
- runPyodide(codeToRun, pyodidePromise);
+ await runPyodide(codeToRun, pyodidePromise);
});
document.querySelector(".parsons-reset").addEventListener("click", resetProblem);
+ await runPyodideSetup(pyodidePromise);
+
});
function getPreviousSiblings(elem, filter) {
diff --git a/textbook/parsons-yaml/homework-1-2.yml b/textbook/parsons-yaml/homework-1-2.yml
index e4578a9..eadb847 100644
--- a/textbook/parsons-yaml/homework-1-2.yml
+++ b/textbook/parsons-yaml/homework-1-2.yml
@@ -1,5 +1,7 @@
+python_setup: |
+ courses = ['CHEM 1001 10', 'CHEM 1001 11', 'BISC 1111 10', 'BISC 2207 10', 'PSC 1001 10',
+ 'PSC 1001 11', 'PSC 1001 12', 'ANTH 3808 10', 'AMST 2071 80']
python_code: |
- courses = ['CHEM 1001 10', 'BISC 1111 10', 'BISC 2207 10']
depts = []
for course in courses:
course_info = course.split()