Reputation: 83
I am writing a program to print the sum of multiple of 3
or 5
less than 1000
. I am using an arithmetic progression to do it. My code is:
def multiple(x,y):
a=(1000-(1000%x) - x)/x +1
b=(995-y)/y +1
c=(1000-(1000%x*y)-x*y)/x*y +1
Sa=int(a/2(2*x+(a-1)*a))
Sb=b/2(2*y+(b-1)*b)
Sc=c/2(2*x*y+(c-1)*x*y)
Sd=Sa+Sb-Sc
print Sd
When I call the function I get the error:
Traceback (most recent call last):
File "<interactive input>", line 1, in <module>
File "C:\Python27\swampy-2.1.7\MULTIPLE.py", line 23, in multiple
Sa=int(a/2(2*x+(a-1)*a))
TypeError: 'int' object is not callable
Please point out the mistake in my code. Thanks.
P.S. Please forgive my "art" of question asking. I am new to Python and StackOverflow, so please bear with me. Thanks!
Upvotes: 1
Views: 162
Reputation: 21435
In Sa=int(a/2(2*x+(a-1)*a))
you forgot a *
to multiply between a/2
and (2*x+(a-1)*a)
You should have Sa=int(a/2*(2*x+(a-1)*a))
.
Also, the same on Sb
and Sc
.
Upvotes: 1