Sum of all numbers in the given range which are divisible by M | Function to find the sum of numbers divisible by M in the given range ; Variable to store the sum ; Running a loop from A to B and check if a number is divisible by i . ; If the number is divisible , then add it to sum ; Return the sum ; Driver code ; A and B define the range M is the dividend ; Printing the result
def sumDivisibles ( A , B , M ) : NEW_LINE INDENT sum = 0 NEW_LINE for i in range ( A , B + 1 ) : NEW_LINE INDENT if ( i % M == 0 ) : NEW_LINE INDENT sum += i NEW_LINE DEDENT DEDENT return sum NEW_LINE DEDENT if __name__ == " _ _ main _ _ " : NEW_LINE INDENT A = 6 NEW_LINE B = 15 NEW_LINE M = 3 NEW_LINE print ( sumDivisibles ( A , B , M ) ) NEW_LINE DEDENT