Skip to content

Commit 79f5c7d

Browse files
author
Philip Guo
committed
more more more
1 parent be1d794 commit 79f5c7d

6 files changed

Lines changed: 55 additions & 34 deletions

File tree

edu-python-questions.js

Lines changed: 40 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,36 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
2727
$(document).ready(function() {
2828
eduPythonCommonInit(); // must call this first!
2929

30+
$("#actualCodeInput").tabby(); // recognize TAB and SHIFT-TAB
31+
$("#testCodeInput").tabby(); // recognize TAB and SHIFT-TAB
32+
3033
$("#pyOutputPane").hide();
3134

3235
// for demo purposes ...
36+
var reverseScript =
37+
"def reverse(lst):\n\
38+
N = len(lst) - 1\n\
39+
for i in range(N/2):\n\
40+
tmp = lst[i]\n\
41+
lst[i] = lst[N-i]\n\
42+
lst[N-i] = tmp\n";
43+
44+
var testCode =
45+
"input = ['a', 'b', 'c', 'd', 'e']\n\
46+
reverse(input)\n";
47+
48+
$("#actualCodeInput").val(reverseScript);
49+
$("#testCodeInput").val(testCode);
50+
51+
$("#showHintHref").click(function() {
52+
$("#HintStatement").html("<b>Hint</b>: Think about swapping pairs of elements.");
53+
return false; // don't reload the page
54+
});
55+
56+
$("#showSolutionHref").click(function() {
57+
$("#SolutionStatement").html("<b>Solution</b>: Swap the first and last elements, then the second and second-to-last elements, etc.");
58+
return false; // don't reload the page
59+
});
3360

3461

3562
$("#executeBtn").attr('disabled', false);
@@ -38,18 +65,24 @@ $(document).ready(function() {
3865
$('#executeBtn').attr('disabled', true);
3966
$("#pyOutputPane").hide();
4067

68+
// concatenate the values from #actualCodeInput and #testCodeInput,
69+
// separated by a comment
70+
var submittedCode = $("#actualCodeInput").val() +
71+
"\n# Everything below here is test code\n" +
72+
$("#testCodeInput").val();
73+
4174
$.post("cgi-bin/web_exec.py",
42-
{user_script : $("#pyInput").val()},
75+
{user_script : submittedCode},
4376
function(traceData) {
44-
renderPyCodeOutput($("#pyInput").val());
77+
renderPyCodeOutput(submittedCode);
4578
processTrace(traceData);
4679

47-
$("#pyInputPane").hide();
48-
$("#pyOutputPane").show();
49-
appMode = 'visualize';
80+
$("#pyInputPane").hide();
81+
$("#pyOutputPane").show();
82+
appMode = 'visualize';
5083

51-
$('#executeBtn').html("Visualize execution");
52-
$('#executeBtn').attr('disabled', false);
84+
$('#executeBtn').html("Visualize execution");
85+
$('#executeBtn').attr('disabled', false);
5386
},
5487
"json");
5588
});

edu-python-tutor.js

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
2929
$(document).ready(function() {
3030
eduPythonCommonInit(); // must call this first!
3131

32+
$("#pyInput").tabby(); // recognize TAB and SHIFT-TAB
33+
3234
$("#pyOutputPane").hide();
3335

3436
$("#executeBtn").attr('disabled', false);
@@ -43,12 +45,12 @@ $(document).ready(function() {
4345
renderPyCodeOutput($("#pyInput").val());
4446
processTrace(traceData);
4547

46-
$("#pyInputPane").hide();
47-
$("#pyOutputPane").show();
48-
appMode = 'visualize';
48+
$("#pyInputPane").hide();
49+
$("#pyOutputPane").show();
50+
appMode = 'visualize';
4951

50-
$('#executeBtn').html("Visualize execution");
51-
$('#executeBtn').attr('disabled', false);
52+
$('#executeBtn').html("Visualize execution");
53+
$('#executeBtn').attr('disabled', false);
5254
},
5355
"json");
5456
});

edu-python.css

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ span {
8181
padding: 0px;
8282
}
8383

84-
#pyInput {
84+
.codeInputPane {
8585
font-size: 12pt;
8686
font-family: Andale mono, monospace;
8787
/*font-weight: bold;*/
@@ -540,8 +540,9 @@ div#heapHeader {
540540

541541
#questionsHeaderPane {
542542
text-align: left;
543-
margin-bottom: 10px;
543+
margin-bottom: 15px;
544544
width: 650px;
545+
border-bottom: 1px solid #bbbbbb;
545546
}
546547

547548
.questionsHeaderStmt {

edu-python.js

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1094,8 +1094,6 @@ function renderPyCodeOutput(codeStr) {
10941094

10951095
// initialization function that should be called when the page is loaded
10961096
function eduPythonCommonInit() {
1097-
$("#pyInput").tabby(); // recognize TAB and SHIFT-TAB
1098-
10991097
$("#jmpFirstInstr").click(function() {
11001098
curInstr = 0;
11011099
updateOutput();

index.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@
6767
Write your Python code here:
6868
<br/>
6969

70-
<textarea id="pyInput" cols="55" rows="20" wrap="off"></textarea>
70+
<textarea class="codeInputPane" id="pyInput" cols="55" rows="20" wrap="off"></textarea>
7171

7272
<p>
7373

question.html

Lines changed: 4 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -60,10 +60,6 @@
6060
<div class="questionsHeaderStmt" id="ProblemStatement"><b>Problem</b>: Write a function that
6161
reverses a list in-place.</div>
6262

63-
<div class="questionsHeaderStmt" id="ExampleStatement"><b>Example</b>: A
64-
list <span id="exampleInputData"></span> should be mutated to look like
65-
<span id="exampleOutputData"></span></div>
66-
6763
<div class="questionsHeaderStmt" id="HintStatement"><a href="#" id="showHintHref">Show hint</a></div>
6864
<div class="questionsHeaderStmt" id="SolutionStatement"><a href="#" id="showSolutionHref">Show solution</a></div>
6965

@@ -74,15 +70,12 @@
7470

7571
<div id="pyInputPane">
7672

77-
<textarea id="pyInput" cols="60" rows="18" wrap="off">
78-
def reverse(lst):
79-
# fill in your code here
73+
<p/>Write your solution code here:<br/>
74+
<textarea class="codeInputPane" id="actualCodeInput" cols="60" rows="18" wrap="off">
8075
</textarea>
8176

82-
<p/>Test code:<br/>
83-
<textarea id="pyInput" cols="60" rows="4" wrap="off">
84-
input = ['a', 'b', 'c', 'd', 'e']
85-
reverse(input)
77+
<p/>Write your test code here:<br/>
78+
<textarea class="codeInputPane" id="testCodeInput" cols="60" rows="4" wrap="off">
8679
</textarea>
8780

8881
<p>
@@ -152,11 +145,6 @@
152145
creating programming tutorials, not for running or debugging
153146
production code.
154147

155-
<p style="margin-top: 8px;"/>Official Python 3 support is coming soon;
156-
for now, try the <a
157-
href="http://netserv.ict.ru.ac.za/python3_viz/">Python 3 fork</a> by
158-
Peter Wentworth.
159-
160148
<p style="margin-top: 8px;"/>
161149
Check out the <a
162150
href="https://github.com/pgbovine/OnlinePythonTutor/">GitHub</a>
@@ -170,4 +158,3 @@
170158

171159
</body>
172160
</html>
173-

0 commit comments

Comments
 (0)