Finished problem number 24 in Python