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:
"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.
|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
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, '*',
> -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
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
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
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
> ...
> -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
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
> ...
>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'
..
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
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
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
14 matches
Mail list logo