Did you take it into class even though you had been told not to?
Maybe that's why the teacher took it away?
If the school doesn't have a ban on 'things that beep in class' and her actions were out of the blue without warning, then it's a bit unfair, she should have handed it back to you at the end of the lesson.
But if you purposely thought "I won't get caught - even though I'm not allowed it", then maybe you need to apologise and arrange for it to be returned as long as you don't take it to her class again.
A lot of schools have a complete ban on tamagotchi's this is because,
1. they annoy teachers/other students and distract you from your lessons.
2. they are at risk of being stolen for which the school can't take responsibility.
3. they can cause arguments/jealousy.
This is the reason that Bandai had to put a pause feature put in as they originally started to cause problems at school. So if they are banned- leave them at home on pause, I know it means thay take longer to grow - but it's better than confiscation!
Quote from Wikipedia.
"Criticism
There has been much criticism over the years over the Tamagotchi. One common criticism includes children taking them to school and using them during classes. This has led schools to ban the product from being allowed to be brought to school. Bandai eventually added a "PAUSE" feature to the Tamagotchi line to solve the problem, but it is still a common issue."