Updated code for Python 3 with backward compatibility

Updated for Python 3 which is also compatible for Python 2.
Also verifying input from user
Merge pull request #1 from rohit2github/master

Updated code for Python 3 with backward compatibility