Can you? Yes.
Should you? No, for two reasons.
First of all, because the teacher can easily get you expelled for that, and second, because if the teacher legitimately earns it, you can report them and maybe even get them fired. And if that's not enough for you, you can punch them with much less repercussion once they have no authority. Thought out revenge is always much better that blunt heat of the moment retaliation.