1

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!

1 Answer 1

1

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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.