Solved Problem27 in python.