Finished reworking problem 12 in python