Chances are, if you are getting out of gym class due to a pregnancy, your parents are going to find out.
I take it you've tested positive. Right? Did you take a home pregnancy test or get one from the clinic? Being pregnant does not mean you cannot be physically active. Instead of running, you might have to walk type of thing. Swimming is great. Often there is no reason in the first few months to modify any safe activities. I know women who have jogged until their due date. I know other women who go to the gym while pregnant. Being pregnant isn't a sickness or disease.
Now, if you get a doctor to write you a note for school, you don't think your parents will find out? Every kid in school will know, you won't be able to keep it a secret. The first thing people are going to ask is, "How did you get out of gym?"
If you truly are pregnant, you need to tell your parents as soon as possible. It will be obvious soon anyway.