mirror of
https://hub.njuu.cf/TheAlgorithms/Python.git
synced 2023-10-11 13:06:12 +08:00
Create sol2.py
This commit is contained in:
parent
c3b8c51822
commit
77f72fbe1f
22
project_euler/problem_10/sol2.py
Normal file
22
project_euler/problem_10/sol2.py
Normal file
@ -0,0 +1,22 @@
|
|||||||
|
#from Python.Math import prime_generator
|
||||||
|
import math
|
||||||
|
from itertools import takewhile
|
||||||
|
|
||||||
|
def primeCheck(number):
|
||||||
|
if number % 2 == 0 and number > 2:
|
||||||
|
return False
|
||||||
|
return all(number % i for i in range(3, int(math.sqrt(number)) + 1, 2))
|
||||||
|
|
||||||
|
def prime_generator():
|
||||||
|
num = 2
|
||||||
|
while True:
|
||||||
|
if primeCheck(num):
|
||||||
|
yield num
|
||||||
|
num+=1
|
||||||
|
|
||||||
|
def main():
|
||||||
|
n = int(input('Enter The upper limit of prime numbers: '))
|
||||||
|
print(sum(takewhile(lambda x: x < n,prime_generator())))
|
||||||
|
|
||||||
|
if __name__ == '__main__':
|
||||||
|
main()
|
Loading…
Reference in New Issue
Block a user