Kinda newb-ish question

Hans Nowak hans at
Fri Dec 12 02:20:56 CET 2003

ChocoboMog123 wrote:
> What's wrong with line 8 in this code?
> x=1
> while 1==1:
>     x=x+1
>     y=range(1,x)
>     z=0
>     q=9
>     for count in y:
>         q=x%y
>         if q==0:
>             z=z+1
>     if z<1:
>         print x
> It keeps giving me 
> Traceback (most recent call last):
>   File "C:\Python23\Prime", line 8, in -toplevel-
>     q=x%y
> TypeError: unsupported operand type(s) for %: 'int' and 'list'

The error message points out what's wrong with it... you're using the % 
operator with an int (x) and a list (y), which is unsupported.  You probably 
mean something like x % count, although that doesn't make the algorithm work.

Quick tips: use range(2,x) rather than range(1,x), and x % count.  An infinite 
loop is probably not a good idea either. :-)


Hans (hans at

More information about the Python-list mailing list