The only 100% guaranteed way to avoid pregnancy is to not have sex. But if you’re going to have sex then you need to make sure you use protection carefully, consistently, and correctly EVERY TIME. There are lots of methods of contraception available to meet your needs. Talk to your doc to find the method that’s right for you.
Don’t forget that condoms are the only method that will protect you from both STIs and pregnancy.