I have got a function:
def euler9():
for b in range(1, 500):
a = (500000 - 1000 * b) / (1000 - b)
if a % 1 == 0:
print(b * a * (1000 - a - b))
And I want to make it in one line like
x*x for x in range(1,1)
This is what I have done:
def euler9():
print([b * a * (1000 - a - b) for b in range(1, 500) for a in (500000 - 1000 * b) / (1000 - b) if a % 1 == 0])
but I do not know what am I doing wrong. I have got an error: TypeError: 'float' object is not iterable
1000 - bdivides500000 - 1000 * b. If so, you should check whether(500000 - 1000 * b) % (1000 - b) == 0, rather than performing a floating-point division and checking whether the result has a fractional part. Floating-point operations involve rounding error that you shouldn't subject yourself to for a purely-integer operation.