how can a doctor tell if a girl has or has not had sex? What is different?
Virgin and nonvirgin
The only thing a doctor can do is see if the hymen is still intact. If it is, then there probably has been no penis-in-vagina sex. But it usually isn't intact nowadays, and that doesn't necessarily mean sex, because it can be broken by a deeply inserted tampon, or many other ways.
If the hymen is broken, the doctor can't tell. If the hymen is intact, the doctor can assume she's a virgin.
All in all, you can't really tell.