Finished problems 5 and 6 in Python