Re: basic python question about for loop

2008-04-12 Thread Steve Holden
jmDesktop wrote: [...] > So what is n and x in the first iteration? Sorry. I'm trying. Somewhat feebly, if you don't mind my saying so, but don't worry. The usual way to proceed in the face of such ignorance is to insert some form of output that will tell you the answer to your question. So:

Re: basic python question about for loop

2008-04-12 Thread Jason Stokes
"jmDesktop" <[EMAIL PROTECTED]> wrote in message news:[EMAIL PROTECTED] > So what is n and x in the first iteration? Sorry. I'm trying. Remember how Python's range operator works. range(n, x) constructs a list that consists of all elements starting with n and up to, but /not including/, x.

Re: basic python question about for loop

2008-04-09 Thread Terry Reedy
|So what is n and x in the first iteration? Sorry. I'm trying. When n == 2, the inner loop executes 0 times (the length of range(2,n)) and then falls thru to the else clause, printing the correct answer. -- http://mail.python.org/mailman/listinfo/python-list

Re: basic python question about for loop

2008-04-09 Thread Diez B. Roggisch
jmDesktop schrieb: > On Apr 9, 4:58 pm, "Diez B. Roggisch" <[EMAIL PROTECTED]> wrote: >> jmDesktop schrieb: >> >> >> >> >> >>> From the Python.org tutorial: >> for n in range(2, 10): >>> ... for x in range(2, n): >>> ... if n % x == 0: >>> ... print n, 'equals', x, '*',

RE: basic python question about for loop

2008-04-09 Thread Reedick, Andrew
> -Original Message- > From: [EMAIL PROTECTED] [mailto:python- > [EMAIL PROTECTED] On Behalf Of jmDesktop > Sent: Wednesday, April 09, 2008 5:04 PM > To: python-list@python.org > Subject: Re: basic python question about for loop > > > > > > >>&g

Re: basic python question about for loop

2008-04-09 Thread jmDesktop
On Apr 9, 4:59 pm, "Reedick, Andrew" <[EMAIL PROTECTED]> wrote: > > -Original Message- > > From: [EMAIL PROTECTED] [mailto:python- > > [EMAIL PROTECTED] On Behalf Of jmDesktop > > Sent: Wednesday, April 09, 2008 4:51 PM > > To: [EMAIL PROTECTED

Re: basic python question about for loop

2008-04-09 Thread jmDesktop
On Apr 9, 4:58 pm, "Diez B. Roggisch" <[EMAIL PROTECTED]> wrote: > jmDesktop schrieb: > > > > > > > From the Python.org tutorial: > > for n in range(2, 10): > > ...     for x in range(2, n): > > ...         if n % x == 0: > > ...             print n, 'equals', x, '*', n/x > > ...             b

Re: basic python question about for loop

2008-04-09 Thread Steve Holden
jmDesktop wrote: >>From the Python.org tutorial: > for n in range(2, 10): > ... for x in range(2, n): > ... if n % x == 0: > ... print n, 'equals', x, '*', n/x > ... break > ... else: > ... # loop fell through without finding a factor > ...

RE: basic python question about for loop

2008-04-09 Thread Reedick, Andrew
> -Original Message- > From: [EMAIL PROTECTED] [mailto:python- > [EMAIL PROTECTED] On Behalf Of jmDesktop > Sent: Wednesday, April 09, 2008 4:51 PM > To: python-list@python.org > Subject: basic python question about for loop > > >From the Python.org tutorial

Re: basic python question about for loop

2008-04-09 Thread Diez B. Roggisch
jmDesktop schrieb: > From the Python.org tutorial: > for n in range(2, 10): > ... for x in range(2, n): > ... if n % x == 0: > ... print n, 'equals', x, '*', n/x > ... break > ... else: > ... # loop fell through without finding a factor > ...

basic python question about for loop

2008-04-09 Thread jmDesktop
>From the Python.org tutorial: >>> for n in range(2, 10): ... for x in range(2, n): ... if n % x == 0: ... print n, 'equals', x, '*', n/x ... break ... else: ... # loop fell through without finding a factor ... print n, 'is a prime number' ..

Re: Question about 'for' loop

2007-08-17 Thread Carsten Haese
On Fri, 2007-08-17 at 17:45 -0500, Robert Dailey wrote: > [...] > Secondly, I'm wondering how I can use this method of a for loop to > append strings to strings in a list. For example: > > mylist = [ > "Hello ", > "Hello again " > ] > > I should be able to do this: > > print [ i + "World" for i

Re: Question about 'for' loop

2007-08-17 Thread Steve Holden
Robert Dailey wrote: > Hi, > > I noticed that the 'for' loop can be used inline with a list definition. > For example: > > print [i for i in mylist] > > My first question is what is the name for this? I couldn't find this > usage in the python docs; I only managed to learn about it through cod

Question about 'for' loop

2007-08-17 Thread Robert Dailey
Hi, I noticed that the 'for' loop can be used inline with a list definition. For example: print [i for i in mylist] My first question is what is the name for this? I couldn't find this usage in the python docs; I only managed to learn about it through code samples on the internet. Secondly, I'm