Fixed xrange compatibility for Python 3

This commit is contained in:
Daniel Ingram 2018-03-19 09:29:46 -04:00
parent 2d2644ee17
commit c6c5d62311
3 changed files with 15 additions and 0 deletions

View File

@ -1,6 +1,11 @@
from __future__ import print_function
from math import sqrt
try:
xrange #Python 2
except NameError:
xrange = range #Python 3
def is_prime(n):
for i in xrange(2, int(sqrt(n))+1):
if n%i == 0:

View File

@ -1,5 +1,10 @@
from __future__ import print_function
try:
xrange #Python 2
except NameError:
xrange = range #Python 3
def fibonacci(n):
if n == 1 or type(n) is not int:
return 0

View File

@ -1,6 +1,11 @@
from __future__ import print_function
from math import ceil
try:
xrange #Python 2
except NameError:
xrange = range #Python 3
def diagonal_sum(n):
total = 1