Re: [Tutor] Else Clause In A Loop

2008-05-14 Thread Simón A. Ruiz
kinuthia muchane wrote: On Tue, 2008-05-13 at 11:09 -0400, "Simón A. Ruiz" wrote: When i is 3, then we'll only check (2 % 3 == 0) which is False, so the loop ends unbroken and runs the else clause letting us know that 3 is indeed a prime number. Shouldn't we be checking for (3%2 == 0) instead

Re: [Tutor] Else Clause In A Loop

2008-05-13 Thread kinuthia muchane
On Tue, 2008-05-13 at 11:09 -0400, "Simón A. Ruiz" wrote: > kinuthia muchane wrote: > > On Mon, 2008-05-12 at 14:08 -0400, "Simón A. Ruiz" wrote: > >> For each of those numbers, it checks to see if any number between 2 and > >> i is divisible into i. If it finds anything, we know it's not a prime

Re: [Tutor] Else Clause In A Loop

2008-05-13 Thread Simón A. Ruiz
kinuthia muchane wrote: On Mon, 2008-05-12 at 14:08 -0400, "Simón A. Ruiz" wrote: For each of those numbers, it checks to see if any number between 2 and i is divisible into i. If it finds anything, we know it's not a prime, and so it breaks out of that second loop without completing it, which

Re: [Tutor] Else Clause In A Loop

2008-05-12 Thread Alan Gauld
"kinuthia muchane" <[EMAIL PROTECTED]> wrote This has served to confuse me more. Would someone please kindly explain how all this fits into the code below which searches (and finds!) for prime numbers... It doesn't find prime numbers very well. It only finds the primes *below* the one enter

Re: [Tutor] Else Clause In A Loop

2008-05-12 Thread kinuthia muchane
On Mon, 2008-05-12 at 14:08 -0400, "Simón A. Ruiz" wrote: > I'll try my hand at this: > > The outside for loop is looking through every number up to the variable > "number". No quarrel here. > > For each of those numbers, it checks to see if any number between 2 and > i is divisible into i. If

Re: [Tutor] Else Clause In A Loop

2008-05-12 Thread Simón A. Ruiz
I'll try my hand at this: The outside for loop is looking through every number up to the variable "number". For each of those numbers, it checks to see if any number between 2 and i is divisible into i. If it finds anything, we know it's not a prime, and so it breaks out of that second loop

[Tutor] Else Clause In A Loop

2008-05-12 Thread kinuthia muchane
Hi, I learnt that a loop can have an else clause. And that this clause executes when the loop TERMINATES. In a while loop when the condition becomes false, and in a for loop when a sequence is exhausted. When I write the following code it seems to work: for n in [1,2,3,4,5]: print 'we are