Adding solutions to problems 4 and 5 in python