python solution for problems 30 and 37