MCPcopy Create free account
hub / github.com/TheAlgorithms/Python / solution

Function solution

project_euler/problem_001/sol5.py:13–28  ·  view source on GitHub ↗

Returns the sum of all the multiples of 3 or 5 below n. A straightforward pythonic solution using list comprehension. >>> solution(3) 0 >>> solution(4) 3 >>> solution(10) 23 >>> solution(600) 83700

(n: int = 1000)

Source from the content-addressed store, hash-verified

11
12
13def solution(n: int = 1000) -> int:
14 """
15 Returns the sum of all the multiples of 3 or 5 below n.
16 A straightforward pythonic solution using list comprehension.
17
18 >>> solution(3)
19 0
20 >>> solution(4)
21 3
22 >>> solution(10)
23 23
24 >>> solution(600)
25 83700
26 """
27
28 return sum(i for i in range(n) if i % 3 == 0 or i % 5 == 0)
29
30
31if __name__ == "__main__":

Callers 1

sol5.pyFile · 0.70

Calls

no outgoing calls

Tested by

no test coverage detected