added python3 compatibility by catching the errors with xrange

see error report. xrange causes traceback in python version 3.4