Fourth problem solved in Python