Skip to content

Commit 123f0b9

Browse files
author
Philip Guo
committed
added another small example and cleaned up HTML slightly
1 parent d1f1c03 commit 123f0b9

3 files changed

Lines changed: 27 additions & 3 deletions

File tree

‎edu-python.js‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -762,6 +762,11 @@ $(document).ready(function() {
762762
return false;
763763
});
764764

765+
$("#pwTryFinallyLink").click(function() {
766+
$.get("example-code/wentworth_try_finally.txt", function(dat) {$("#pyInput").val(dat);});
767+
return false;
768+
});
769+
765770

766771
// select an example on start-up:
767772
$("#tutorialExampleLink").trigger('click');
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
# Tutorial code from Prof. Peter Wentworth
2+
# Rhodes University, South Africa (http://www.ru.ac.za/)
3+
4+
# Demonstrate recursion that throws an exception
5+
# at its base case, and the tracing of try ... finally.
6+
#
7+
# How many "survived!" messages will be printed???
8+
9+
def f(n):
10+
try:
11+
x = 10 / n
12+
print "x is", x
13+
f(n-1)
14+
print "survived!"
15+
finally:
16+
print "Bye from f where n =", n
17+
18+
f(4)

‎index.html‎

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@
7070

7171
<p style="margin-top: 25px;">Try these small examples:<br/>
7272

73-
<a id="tutorialExampleLink" href="#">Python intro</a> |
73+
<a id="tutorialExampleLink" href="#">intro</a> |
7474
<a id="factExampleLink" href="#">factorial</a> |
7575
<a id="fibonacciExampleLink" href="#">fibonacci</a> |
7676
<a id="memoFibExampleLink" href="#">memoized fib</a> |
@@ -81,12 +81,13 @@
8181
<a id="aliasExampleLink" href="#">aliasing</a> |
8282
<a id="oopSmallExampleLink" href="#">OOP</a> |
8383
<a id="pwGcdLink" href="#">gcd</a> |
84-
<a id="pwSumListLink" href="#">sumList</a>
84+
<a id="pwSumListLink" href="#">sumList</a> |
85+
<a id="pwTryFinallyLink" href="#">exceptions</a>
8586

8687
</p>
8788

8889
<p style="margin-top: 25px;">Examples from the MIT
89-
<a href="http://mit.edu/6.01/mercurial/spring10/www/">6.01</a> course:<br/>
90+
<a href="http://mit.edu/6.01/">6.01</a> course:<br/>
9091

9192
<a id="mapExampleLink" href="#">list map</a> |
9293
<a id="sumExampleLink" href="#">summation</a> |

0 commit comments

Comments
 (0)