Adding problem 29 in Python