Python solution for number 7
Python solution for number 8