mirror of
https://github.com/TheAlgorithms/Python.git
synced 2024-12-01 00:41:09 +00:00
Fixed xrange compatibility for Python 3
This commit is contained in:
parent
2d2644ee17
commit
c6c5d62311
|
@ -1,6 +1,11 @@
|
||||||
from __future__ import print_function
|
from __future__ import print_function
|
||||||
from math import sqrt
|
from math import sqrt
|
||||||
|
|
||||||
|
try:
|
||||||
|
xrange #Python 2
|
||||||
|
except NameError:
|
||||||
|
xrange = range #Python 3
|
||||||
|
|
||||||
def is_prime(n):
|
def is_prime(n):
|
||||||
for i in xrange(2, int(sqrt(n))+1):
|
for i in xrange(2, int(sqrt(n))+1):
|
||||||
if n%i == 0:
|
if n%i == 0:
|
||||||
|
|
|
@ -1,5 +1,10 @@
|
||||||
from __future__ import print_function
|
from __future__ import print_function
|
||||||
|
|
||||||
|
try:
|
||||||
|
xrange #Python 2
|
||||||
|
except NameError:
|
||||||
|
xrange = range #Python 3
|
||||||
|
|
||||||
def fibonacci(n):
|
def fibonacci(n):
|
||||||
if n == 1 or type(n) is not int:
|
if n == 1 or type(n) is not int:
|
||||||
return 0
|
return 0
|
||||||
|
|
|
@ -1,6 +1,11 @@
|
||||||
from __future__ import print_function
|
from __future__ import print_function
|
||||||
from math import ceil
|
from math import ceil
|
||||||
|
|
||||||
|
try:
|
||||||
|
xrange #Python 2
|
||||||
|
except NameError:
|
||||||
|
xrange = range #Python 3
|
||||||
|
|
||||||
def diagonal_sum(n):
|
def diagonal_sum(n):
|
||||||
total = 1
|
total = 1
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user