Why do you have a ozone layer?

We have an ozone layer because without it the Earth would be way too cold for there to be life on it.