Python solution for problem 5
Pythong solution for number 6