Click here to Skip to main content
15,072,753 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Write a plan so that you print the sum of all the numbers 100 between 1000 divided by exactly 12.
its need to print 41,392 but its print 41,400
someone can fix me please?

What I have tried:

Python
def sumDivisibles(A, B, M):
 
    sum = 0
 
    for i in range(A, B + 1):
 
        if (i % M == 0):
            sum += i
 
    return sum
 
if __name__=="__main__":
     
    A = 100
    B = 1000
    M = 12
 
    print(sumDivisibles(A, B, M))
Posted
Updated 13-Aug-21 2:17am
v2

Quote:
its need to print 41,392 but its print 41,400

The sum of integers divisible by 12 is itself divisible by 12.
41,392 is not divisible by 12. Looks like the problem is in your expectation.
   
Comments
Tomer Oved 13-Aug-21 7:51am
   
can you help me please?
Patrice T 13-Aug-21 7:58am
   
There is no help, you expect a result that is wrong !
The numbers between 100 and 1000 inclusive that are exactly divisible by 12 do not sum to 41392, they sum to 41400:
108 120 132 144 156 168 180 192 204 216 
228 240 252 264 276 288 300 312 324 336 
348 360 372 384 396 408 420 432 444 456 
468 480 492 504 516 528 540 552 564 576 
588 600 612 624 636 648 660 672 684 696 
708 720 732 744 756 768 780 792 804 816 
828 840 852 864 876 888 900 912 924 936 
948 960 972 984 996

So the problem is not the code, and is not "fixable" unless you can change the way teh universe works - the question is wrong!
   

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)




CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900