Changed Code Structure - Functionality is same

Well, I have removed some repetative lines by making a function for the
same. This function will be addressing the keyboard calls and also will
make the code more pythonic. :D