Finalized Python Code. Needs Debugging.