Solved problem 24

In Python