Problem four in python