Sean Morgan Sean Morgan - 1 year ago 80
Python Question

Why does Python say "Inappropriate Argument Type" for xrange?

My code is:

def euler7():
for num in xrange(3, 9999999999, 2):
for n in xrange(1, num):
if num%n==0:
if numb==1:
if prime==10001:
return val

But, it says there is an Inappropriate argument type for the for loops. I dont know if that means that it is not seeing the values as integers, or what is happening. Thanks

Answer Source

xrange won't work with large numbers since the code is executed as a C program (

According to docs -

CPython implementation detail: xrange() is intended to be simple and fast. Implementations may impose restrictions to achieve this. The C implementation of Python restricts all arguments to native C longs (“short” Python integers), and also requires that the number of elements fit in a native C long. If a larger range is needed, an alternate version can be crafted using the itertools module: islice(count(start, step), (stop-start+step-1+2*(step<0))//step).

I am not sure what system specs you got, but generally c int is 2^16-1 and c long is 2^32-1.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download