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]
> > Subject: basic python question about for
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:
>
> >>> for n in range(2, 1
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
> ...
10 matches
Mail list logo