uti and sex?

Can I still have sex if I have a uti??
I've been given medication to take over 3 days .
Should I wait them 3 days ...  and then have sex or is it ok to anyway ?
Also what prevents a uti