Kinda newb-ish question
Hans Nowak
hans at zephyrfalcon.org
Thu Dec 11 20:20:56 EST 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 Number.py", 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. :-)
HTH,
--
Hans (hans at zephyrfalcon.org)
http://zephyrfalcon.org/
More information about the Python-list
mailing list