Corredted some errors and canged range() function according to python 3.x.