File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff 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' ) ;
Original file line number Diff line number Diff line change 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)
Original file line number Diff line number Diff line change 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 > |
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 > |
You can’t perform that action at this time.
0 commit comments