Problem 8 in python. Not bad