Problem with following python code

Tim Leslie tim.leslie at gmail.com
Tue Jun 12 00:50:47 EDT 2007


On 6/12/07, why? <jimbomaan at yahoo.com> wrote:
> I've been having problem with the following code. It's supposed to
> print the prime numbers  between 10 and 100. But i'm not getting any
> output, i.e. i guess the outer 'for' loop is being traversed only
> once. I would be greatful if you could help me out. Thanx!
> >>> f=1
> >>> for i in range(10,100):

You need to switch these two lines to reset the flag each time around
the outer loop.

Cheers,

Tim

> ...     for j in range(2,i):
> ...             if i%j==0:
> ...                     f=0
> ...                     break
> ...             else: continue
> ...     if f==1:
> ...             print i,
> ...
>
> --
> http://mail.python.org/mailman/listinfo/python-list
>



More information about the Python-list mailing list