Add solution for problem 6 in Python. Fix implementation of previous problems.