Write a function that accepts an integer (n)
and calculates the multiples of 4 or 6 up to n
but not including the input number n
.
Return the sum of those multiples.
For example:
n = 20 ==> 64
n = 35 ==> 198
n = 120 ==> 2340
def find_multiples(n): total = 0 for i in range(0, n, 2): if i % 4 == 0 or i % 6 == 0: total += i return total
- def find_multiples(n):
- total = 0
- for i in range(0, n, 2):
- if i % 4 == 0 or i % 6 == 0:
- total += i
return total- return total
import codewars_test as test import solution # or from solution import example @test.describe("Example") def test_group(): @test.it("test case") def test_case(): test.assert_equals(find_multiples(20), 64) test.assert_equals(find_multiples(35), 198) test.assert_equals(find_multiples(120), 2340) test.assert_equals(find_multiples(999999), 166665833334)
- import codewars_test as test
- import solution # or from solution import example
- @test.describe("Example")
- def test_group():
- @test.it("test case")
- def test_case():
- test.assert_equals(find_multiples(20), 64)
- test.assert_equals(find_multiples(35), 198)
- test.assert_equals(find_multiples(120), 2340)
- test.assert_equals(find_multiples(999999), 166665833334)