Re: [Tutor] Two subsequent for loops in one function - I got it!

2013-11-23 Thread Steven D'Aprano
On Sat, Nov 23, 2013 at 08:57:54PM +0100, Rafael Knuth wrote: > I have only one question left. > Here's my original program again: > > for x in range(2, 10): > for y in range(2, x): > if x % y == 0: > print(x, "equals", y, "*", x//y) > break > else: >

Re: [Tutor] Two subsequent for loops in one function - I got it!

2013-11-23 Thread Steven D'Aprano
On Sat, Nov 23, 2013 at 09:54:38PM +0100, Rafael Knuth wrote: > > See? It has no output. By the way, the python REPL is your friend! > > Use it often when you can't figure out what is happening. > > Oh, I didn't even know that such a thing exists :-) Cool! > Unfortunately, I only found Python REP

Re: [Tutor] Two subsequent for loops in one function - I got it!

2013-11-23 Thread Alan Gauld
On 23/11/13 20:54, Rafael Knuth wrote: See? It has no output. By the way, the python REPL is your friend! Unfortunately, I only found Python REPLs for version 2.7.2 or lower. Is there a REPL for 3.3.0 ..? The REPL (read–eval–print loop) is the >>> prompt. You type stuff in and Python reads

Re: [Tutor] Two subsequent for loops in one function - I got it!

2013-11-23 Thread Rafael Knuth
> See? It has no output. By the way, the python REPL is your friend! Use it > often when you can't figure out what is happening. Oh, I didn't even know that such a thing exists :-) Cool! Unfortunately, I only found Python REPLs for version 2.7.2 or lower. Is there a REPL for 3.3.0 ..? Thanks, R

Re: [Tutor] Two subsequent for loops in one function - I got it!

2013-11-23 Thread Don Jennings
On Nov 23, 2013, at 2:57 PM, Rafael Knuth wrote: > > The output of > >for y in range (2,2): > > should be ... none - correct? No, it's not none. It's an empty list; thus, python executes nothing inside the inner loop. >>> range(2,2) [] >>> for y in range(2,2): ... print 'yes, I m

[Tutor] Two subsequent for loops in one function - I got it!

2013-11-23 Thread Rafael Knuth
@Peter @Steven @Don @Danny thank you *so much" for explaining the concept of a nested for loop! Your simplified example Steven made it very clear to me: for x in range(2, 7): print("outer loop, x =", x) for y in range(2, x): print("inner loop, x =", x, "y =", y) I have only one q

Re: [Tutor] Two subsequent for loops in one function

2013-11-22 Thread Danny Yoo
I agree with Peter Otten. I want to try restating what he said to try to emphasize what I think is the key point. One basic skill that you learn as a programmer is how to handle nesting. One strategy is to give things names. This can have benefits: 1. The name itself might make the code ea

Re: [Tutor] Two subsequent for loops in one function

2013-11-22 Thread Don Jennings
On Nov 22, 2013, at 9:24 AM, Rafael Knuth wrote: > Hej there, > > newbie question: I struggle to understand what exactly those two > subsequent for loops in the program below do (Python 3.3.0): > > for x in range(2, 10): >for y in range(2, x): >if x % y == 0: >print(x, "

Re: [Tutor] Two subsequent for loops in one function

2013-11-22 Thread Steven D'Aprano
On Fri, Nov 22, 2013 at 03:24:31PM +0100, Rafael Knuth wrote: > Hej there, > > newbie question: I struggle to understand what exactly those two > subsequent for loops in the program below do (Python 3.3.0): > > for x in range(2, 10): > for y in range(2, x): > if x % y == 0: >

Re: [Tutor] Two subsequent for loops in one function

2013-11-22 Thread Peter Otten
Rafael Knuth wrote: > Hej there, > > newbie question: I struggle to understand what exactly those two > subsequent for loops in the program below do (Python 3.3.0): > > for x in range(2, 10): > for y in range(2, x): > if x % y == 0: > print(x, "equals", y, "*", x//y) >

[Tutor] Two subsequent for loops in one function

2013-11-22 Thread Rafael Knuth
Hej there, newbie question: I struggle to understand what exactly those two subsequent for loops in the program below do (Python 3.3.0): for x in range(2, 10): for y in range(2, x): if x % y == 0: print(x, "equals", y, "*", x//y) break else: print(x