layout | title |
---|---|
default |
Multiple Parson's Problems on One Page |
Re-arrange the blocks below so they print out "Hello World!"
<script type="text/javascript"> (function() { var initial = "print(\"Hello\")\n" + "print(\" \")\n" + "print(\"World\")\n" + "print(\"!\")"; var parsonsPuzzle = new ParsonsWidget({ "sortableId": "p1-sortable", "max_wrong_lines": 10, "grader": ParsonsWidget._graders.LineBasedGrader, "exec_limit": 2500, "can_indent": false, "x_indent": 50, "lang": "en", "trashId": "p1-sortableTrash" }); parsonsPuzzle.init(initial); parsonsPuzzle.shuffleLines(); $("#p1-newInstanceLink").click(function(event){ event.preventDefault(); parsonsPuzzle.shuffleLines(); }); $("#p1-feedbackLink").click(function(event){ event.preventDefault(); parsonsPuzzle.getFeedback(); }); })(); </script>
Construct a program that swaps the values of variables x
and y
using the helper variable tmp
. You can change the names of the variables () by clicking them.
<script type="text/javascript"> (function(){ var initial = "$$toggle::x::y::tmp$$ = $$toggle::x::y::tmp$$\n" + "$$toggle::x::y::tmp$$ = $$toggle::x::y::tmp$$\n" + "$$toggle::x::y::tmp$$ = $$toggle::x::y::tmp$$"; var parsonsPuzzle = new ParsonsWidget({ "sortableId": "p2-sortable", "max_wrong_lines": 10, "grader": ParsonsWidget._graders.VariableCheckGrader, "exec_limit": 2500, "can_indent": true, "x_indent": 50, "lang": "en", "trashId": "p2-sortableTrash", "vartests": [ { "message": "Testing with initial variable values x = 3 and y = 4", "initcode": "x = 3\ny = 4", "code": "", "variables": {} }, { "message": "Testing with initial variable values x = 0 and y = 2", "initcode": "x = 0\ny = 2", "code": "", "variables": {} } ] }); parsonsPuzzle.init(initial); parsonsPuzzle.shuffleLines(); $("#p2-newInstanceLink").click(function(event){ event.preventDefault(); parsonsPuzzle.shuffleLines(); }); $("#p2-feedbackLink").click(function(event){ event.preventDefault(); parsonsPuzzle.getFeedback(); }); })(); </script>
Your task is to construct a function which returns the index of the largest element in the array.
<script type="text/javascript"> (function(){ var initial = "def maxindex(arg):\n" + " ans = 0\n" + " for i in range(len(arg)):\n" + " if arg[i] > arg[ans]:\n" + " ans = i\n" + " while True:\n" + "pass\n" + " return ans"; var parsonsPuzzle = new ParsonsWidget({ "sortableId": "p3-sortable", "max_wrong_lines": 10, "grader": ParsonsWidget._graders.UnitTestGrader, "exec_limit": 2500, "can_indent": true, "x_indent": 50, "lang": "en", "trashId": "p3-sortableTrash", "unittests": "import unittestparson\nclass myTests(unittestparson.unittest):\n def test_0(self):\n self.assertEqual(,,)\n_test_result = myTests().main()" }); parsonsPuzzle.init(initial); parsonsPuzzle.shuffleLines(); $("#p3-newInstanceLink").click(function(event){ event.preventDefault(); parsonsPuzzle.shuffleLines(); }); $("#p3-feedbackLink").click(function(event){ event.preventDefault(); parsonsPuzzle.getFeedback(); }); })(); </script>
Print out "I am a Java program" three times using a for loop.
<script type="text/javascript"> (function(){ var initial = "for (int i=0;i<3;i++) {\n" + "System.out.print(\\\"I \\\");\n" + "System.out.print(\\\"am \\\");\n" + "System.out.print(\\\"a Java program \\\");\n" + "}"; var parsonsPuzzle = new ParsonsWidget({ "sortableId": "p4-sortable", "max_wrong_lines": 1, "grader": ParsonsWidget._graders.LanguageTranslationGrader, "exec_limit": 2500, "can_indent": true, "x_indent": 50, "lang": "en", "executable_code": "for x in range(3):\n output += 'I '\n output += 'am '\n output += 'a Java program '\npass", "programmingLang": "java", "vartests": [ { "message": "Testing...", "initcode": "output = ''", "code": "", "variables": { "output": "I am a Java program I am a Java program I am a Java program " } } ] }); parsonsPuzzle.init(initial); parsonsPuzzle.shuffleLines(); $("#p4-newInstanceLink").click(function(event){ event.preventDefault(); parsonsPuzzle.shuffleLines(); }); $("#p4-feedbackLink").click(function(event){ event.preventDefault(); parsonsPuzzle.getFeedback(); }); })(); </script>
Construct a program by dragging&dropping and reordering lines. The constructed program should draw a triangle like shown below.
<script type="text/javascript"> (function(){ var initial = "REPEAT 3 TIMES\n" + " forward(100)\n" + " left(120)\n" + "ENDREPEAT"; var parsonsPuzzle = new ParsonsWidget({ "sortableId": "p5-sortable", "max_wrong_lines": 1, "grader": ParsonsWidget._graders.TurtleGrader, "exec_limit": 2500, "can_indent": true, "x_indent": 50, "lang": "en", "trashId": "p5-sortableTrash", "executable_code": "for i in range(0,3):\nmyTurtle.forward(100)\nmyTurtle.left(120)\npass", "programmingLang": "pseudo", "turtleModelCode": "modelTurtle.forward(100)\nmodelTurtle.left(120)\nmodelTurtle.forward(100)\nmodelTurtle.left(120)\nmodelTurtle.forward(100)\nmodelTurtle.left(120)", }); parsonsPuzzle.init(initial); parsonsPuzzle.shuffleLines(); $("#p5-newInstanceLink").click(function(event){ event.preventDefault(); parsonsPuzzle.shuffleLines(); }); $("#p5-feedbackLink").click(function(event){ event.preventDefault(); parsonsPuzzle.getFeedback(); }); })(); </script>
When you host multiple Parson's problems on a single markdown page, you need to add a unique prefix. You can easily do this in the Codio generator by typing a unique prefix into the "Prefix" textbox and pressing Enter/Return. Then you can simply copy-paste like normal.
If want each problem to be it's own page, you can use relative path links at the bottom of each of your markdown pages as seen below. If you want students to be able to return to previous problems in this format, consider adding previous links or link to a table of contents like page.