How can I go about grabbing the numerator and the denominator separately from a fraction.

I want to have an input which will be a fraction with polynomials in the numerator and in the denominator. I would like to factor both of the num and denom and then place them back into the fraction and have it print to the screen.

Getting into a fraction is easy, I can't seem to figure out how to take them apart.

Thanks for any help I am fairly new to Python.