solution of codingbat in python