Changed range() function according to python3 and corrected some errors

1> Corrected some errors for Python 3.x
2> Changed range() function according to Python 3.x.