Simplify code by dropping support for legacy Python (#1143)

* Simplify code by dropping support for legacy Python

* sort() --> sorted()
This commit is contained in:
Christian Clauss
2019-08-19 15:37:49 +02:00
committed by GitHub
parent 32aa7ff081
commit 47a9ea2b0b
145 changed files with 367 additions and 976 deletions

View File

@ -4,22 +4,11 @@ The sum of the primes below 10 is 2 + 3 + 5 + 7 = 17.
Find the sum of all the primes below two million.
"""
from __future__ import print_function
from math import sqrt
try:
raw_input # Python 2
except NameError:
raw_input = input # Python 3
try:
xrange # Python 2
except NameError:
xrange = range # Python 3
def is_prime(n):
for i in xrange(2, int(sqrt(n)) + 1):
for i in range(2, int(sqrt(n)) + 1):
if n % i == 0:
return False
@ -32,7 +21,7 @@ def sum_of_primes(n):
else:
return 0
for i in xrange(3, n, 2):
for i in range(3, n, 2):
if is_prime(i):
sumOfPrimes += i
@ -41,7 +30,7 @@ def sum_of_primes(n):
def solution(n):
"""Returns the sum of all the primes below n.
# The code below has been commented due to slow execution affecting Travis.
# >>> solution(2000000)
# 142913828922
@ -58,4 +47,4 @@ def solution(n):
if __name__ == "__main__":
print(solution(int(raw_input().strip())))
print(solution(int(input().strip())))

View File

@ -4,15 +4,9 @@ The sum of the primes below 10 is 2 + 3 + 5 + 7 = 17.
Find the sum of all the primes below two million.
"""
from __future__ import print_function
import math
from itertools import takewhile
try:
raw_input # Python 2
except NameError:
raw_input = input # Python 3
def primeCheck(number):
if number % 2 == 0 and number > 2:
@ -30,7 +24,7 @@ def prime_generator():
def solution(n):
"""Returns the sum of all the primes below n.
# The code below has been commented due to slow execution affecting Travis.
# >>> solution(2000000)
# 142913828922
@ -47,4 +41,4 @@ def solution(n):
if __name__ == "__main__":
print(solution(int(raw_input().strip())))
print(solution(int(input().strip())))