Use python to solve a brain teasers