[Edu-sig] Understanding [ [ ], [ ] ]

2010-04-26 Thread David MacQuigg
Here are some challenges to test students' understanding of how Python handles objects in memory. Scroll down one line at a time and see if you can guess True or False on each equality or identity test. ### More on copying of complex objects >>> from copy import copy, deepcopy # functions fo

[Edu-sig] understanding recursion. . .

2007-02-07 Thread Andy Judkis
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 curiou

Re: [Edu-sig] understanding recursion. . .

2007-02-08 Thread Lloyd Hugh Allen
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 m

Re: [Edu-sig] understanding recursion. . .

2007-02-08 Thread Andre Roberge
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 en

Re: [Edu-sig] understanding recursion. . .

2007-02-08 Thread Andrew Harrington
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 nas

Re: [Edu-sig] understanding recursion. . .

2007-02-08 Thread Phillip Kent
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.html This page has free download of the book PDF. - Phillip ++ Dr Phillip Ke

Re: [Edu-sig] understanding recursion. . .

2007-02-08 Thread kirby urner
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

Re: [Edu-sig] understanding recursion. . .

2007-02-08 Thread Matthew Schinckel
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 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 in pyt

Re: [Edu-sig] understanding recursion

2007-02-09 Thread John Posner
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?") >

Re: [Edu-sig] understanding recursion

2007-02-09 Thread Dethe Elza
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 ov

Re: [Edu-sig] understanding recursion

2007-02-10 Thread kirby urner
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 already

Re: [Edu-sig] understanding recursion

2007-02-12 Thread John Posner
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*

Re: [Edu-sig] understanding recursion

2007-02-12 Thread Richard Holbert
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 ___

Re: [Edu-sig] understanding recursion

2007-02-12 Thread kirby urner
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

Re: [Edu-sig] understanding recursion

2007-02-19 Thread Michel Paul
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

Re: [Edu-sig] understanding recursion

2007-02-19 Thread kirby urner
> 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, g

Re: [Edu-sig] understanding recursion

2007-02-20 Thread Michel Paul
ssage- From: kirby urner [mailto:[EMAIL PROTECTED] Sent: Mon 02/19/07 10:05 PM To: Michel Paul Cc: edu-sig@python.org; Jane Wortman; Lee Morris Subject: Re: [Edu-sig] understanding recursion > The important thing in these exercises is that we can't use our typical > arithmetic >

Re: [Edu-sig] understanding recursion

2007-02-20 Thread kirby urner
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. Thos