Skip to content

Commit c6c5d62

Browse files
Fixed xrange compatibility for Python 3
1 parent 2d2644e commit c6c5d62

File tree

3 files changed

+15
-0
lines changed

3 files changed

+15
-0
lines changed

Project Euler/Problem 10/sol1.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
11
from __future__ import print_function
22
from math import sqrt
33

4+
try:
5+
xrange #Python 2
6+
except NameError:
7+
xrange = range #Python 3
8+
49
def is_prime(n):
510
for i in xrange(2, int(sqrt(n))+1):
611
if n%i == 0:

Project Euler/Problem 25/sol1.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
from __future__ import print_function
22

3+
try:
4+
xrange #Python 2
5+
except NameError:
6+
xrange = range #Python 3
7+
38
def fibonacci(n):
49
if n == 1 or type(n) is not int:
510
return 0

Project Euler/Problem 28/sol1.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
11
from __future__ import print_function
22
from math import ceil
33

4+
try:
5+
xrange #Python 2
6+
except NameError:
7+
xrange = range #Python 3
8+
49
def diagonal_sum(n):
510
total = 1
611

0 commit comments

Comments
 (0)