solve 5 & 6 by py