[Edu-sig] a short essay about programming

2012-04-21 Thread kirby urner
A common error (not too serious) that I see in beginning Python (and no doubt other languages, but Python is the one I'm teaching), is having a while condition that appears to put a lid on things, but then the flow all leaks away through break statements, such that the front door condition is

Re: [Edu-sig] a short essay about programming

2012-04-21 Thread John Zelle
Kirby, There are some nice thoughts here that I don't really disagree with, but your code examples don't use the while conditions well. If you put a condition on the loop, there should be no reason to retest the same condition inside the loop. Think of the loop condition as a guard, inside the

Re: [Edu-sig] a short essay about programming

2012-04-21 Thread John Zelle
Oops, I think I have an off by one error in my last example. I would change the conditional at the bottom to: if guess == secret: print(You guessed it!) else: print(You maxed out.) That's clearer anyway. John Zelle, PhD Professor of Computer Science Wartburg College

[Edu-sig] MemoryError?

2012-04-21 Thread Litvin
Can someone please explain why n = 5000 lst = [i for i in range(n)] # or xrange(n) in Python 2 crashes with MemoryError on a 32-bit system, while n = 5000 lst = n*[0] for i in range(n): # or xrange(n) in Python 2 lst[i] = i works? Thanks, Gary Litvin www.skylit.com

Re: [Edu-sig] a short essay about programming

2012-04-21 Thread A. Jorge Garcia
I always teach my kids about sentinel loops. I have them avoid breaking loops at all costs! What about do loop untils? -- Sent from my Android phone with K-9 Mail. Please excuse my brevity. John Zelle john.ze...@wartburg.edu wrote: Oops, I think I have an off by one error in my last example. I

Re: [Edu-sig] MemoryError?

2012-04-21 Thread David MacQuigg
No problem with Python 2.7.3 on a MacBookPro with 2GB memory and a light load of other programs.  Could it be dependent on how much memory you have available?   There might be slight differences in the memory consumption in computing the two different forms.  I would guess the second form

Re: [Edu-sig] a short essay about programming

2012-04-21 Thread kirby urner
On Sat, Apr 21, 2012 at 6:11 AM, John Zelle john.ze...@wartburg.edu wrote: Kirby, There are some nice thoughts here that I don't really disagree with, but your code examples don't use the while conditions well. If you put a condition on the loop, there should be no reason to retest the same

Re: [Edu-sig] a short essay about programming

2012-04-21 Thread kirby urner
... another useful contribution to this thread. -- Forwarded message -- From: Richard Pattis pat...@ics.uci.edu Date: Sat, Apr 21, 2012 at 6:53 PM Subject: I'm not allowed to post To: kirby urner kirby.ur...@gmail.com Feel free to post this for me, which got returned. Probably

Re: [Edu-sig] a short essay about programming

2012-04-21 Thread John Zelle
Hi All, Interesting thread. Sorry about the extraneous parentheses in my initial post, I've just come off a semester of Java and am reflexively putting parentheses around my conditions. One last thought. While I sometimes use the infinite loop form (while True:) I think the explicit loop