Code  for problem 7, works