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

Function solution

project_euler/problem_010/sol2.py:65–79  ·  view source on GitHub ↗

Returns the sum of all the primes below n. >>> solution(1000) 76127 >>> solution(5000) 1548136 >>> solution(10000) 5736396 >>> solution(7) 10

(n: int = 2000000)

Source from the content-addressed store, hash-verified

63
64
65def solution(n: int = 2000000) -> int:
66 """
67 Returns the sum of all the primes below n.
68
69 >>> solution(1000)
70 76127
71 >>> solution(5000)
72 1548136
73 >>> solution(10000)
74 5736396
75 >>> solution(7)
76 10
77 """
78
79 return sum(takewhile(lambda x: x < n, prime_generator()))
80
81
82if __name__ == "__main__":

Callers 1

sol2.pyFile · 0.70

Calls 1

prime_generatorFunction · 0.70

Tested by

no test coverage detected