Kinda newb-ish question
hans at zephyrfalcon.org
Fri Dec 12 02:20:56 CET 2003
> What's wrong with line 8 in this code?
> while 1==1:
> for count in y:
> if q==0:
> if z<1:
> print x
> It keeps giving me
> Traceback (most recent call last):
> File "C:\Python23\Prime Number.py", line 8, in -toplevel-
> 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 zephyrfalcon.org)
More information about the Python-list