On 2/20/07, Michel Paul [EMAIL PROTECTED] wrote:
snip
We can define gcf prior to defining division or mod. I think that's kind of
interesting. But certainly, outside the scope of this set of exercises, it
makes sense to use looping constructs, and Guido's gcf is pure beauty.
Those moving
I'd like to share an idea that occurred to me awhile back.
It's a problem one can pose prior to discussing any specific programming
language.
Given two black-box functions prev(n) and next(n), along with conditional
reasoning and the typical math comparison operators, define arithmetic.
So for
The important thing in these exercises is that we can't use our typical
arithmetic operators of +, -, *, /, as we are DEFINING them!
I think a Pythoneer will twistedly think at this point is: why do you
say can't use we can can just *redefine* __add__, __sub__, other
__ribs__, to suit, get
Kirby offered Euclid's Algorithm as an example of a recursive function:
def gcd(a,b):
if b:
return gcd(b, a % b)
return a
This example *is* wondrous for demonstrating recursion, because it's so
elegant and terse. But IMHO, these qualities make it less than ideal for
*teaching*
Here's another example of recursion:
def is_a_palindrome(t):
# check to see if t is a palindrome
if (len(t) = 2):
return (t[0] == t[-1]) and is_a_palindrome(t[1:-1])
else:
# t is either a single character, or empty string
return True
Another problem (both with Kirby's implementation and mine) is that you
get
lucky: if the user specifies the smaller number and the larger number in
the wrong order, the algorithm magically swaps them for the next
recursion. When tackling other recursion problems, students probably won't
be
A recent thread on recursion math-thinking-l might be of interest.
Many pro computer scientists like to teach about it in tandem with
Peano Arithmetic (PA) i.e. mathematical induction.
http://mail.geneseo.edu/pipermail/math-thinking-l/2007-January/date.html
Of course if the students are
Andy Judkis [EMAIL PROTECTED] wrote:
... I've found that many kids seem to have a natural ability
to use recursion, but they don't realize that they're doing it, and
they don't understand the implications.
...
def play_game():
. . .
resp = raw_input(Play again?)
if resp
Here's my 0.02. Take with a grain of salt, I've been feverish with
the flu the last couple of days
When the issue comes up, why not step away from the computers and
simply draw a stack on the whiteboard? Show how looping stays at the
same place in the stack and recursion will eventually
iirc, the classic would be to compute fibonaccis recursively and watch
the system grind to a halt in only a handful of iterations. When
googling for recursive fibonacci, I thought that the last example on
the first page http://blogs.msdn.com/ericlippert/archive/2004/05/19/135392.aspx
would tell me
On 2/8/07, Andy Judkis [EMAIL PROTECTED] wrote:
I teach a serious computer literacy course to 10th graders. The course
covers some things about how hardware works, how the internet works, what
operating systems do, etc. The last part is a 3-4 week intro to Python
programming. I've
Andy,
In the situation that you list, recursion is a natural approach. It has
a natural end. there are alternatives, that you may or may not want to
take time to mention.
I have a problem with introductory students doing a major project before
recursion is introduced, and naively having a
It maybe relevant to mention a classic introduction to recursion by Brian
Harvey in the books Computer Science Logo Style
http://www.cs.berkeley.edu/~bh/v1-toc2.htmlhttp://www.cs.berkeley.edu/%7Ebh/v1-toc2.html
This page has free download of the book PDF.
- Phillip
++
Dr Phillip Kent,
Andy:
But they don't have any clue that there's a call stack involved, or that
someday this could get them in trouble. I shudder to think about the
blank looks that I will get if I try to explain why it could be a problem.
I'd praise those stumbling on recursion, use the opportunity to talk
I used recursion a while ago (in JavaScript) using strings. I don't
have the code handy, but I do recall the context. I needed to find
the form element that was the parent/grandparent/great-grand-parent
of the current element. I didn't know how many levels I needed to go
up.
To paraphrase it
I teach a serious computer literacy course to 10th graders. The course
covers some things about how hardware works, how the internet works, what
operating systems do, etc. The last part is a 3-4 week intro to Python
programming. I've encountered some interesting student behavior and I'm
curious
16 matches
Mail list logo