In [1]:
from IPython.display import display, Math

for i in range(0,5):
    for j in range(-3,0):
        if i!=0 and j!=0:
            display(Math('%g^{%g} = %g' %(i,j,i**j)))
$\displaystyle 1^{-3} = 1$
$\displaystyle 1^{-2} = 1$
$\displaystyle 1^{-1} = 1$
$\displaystyle 2^{-3} = 0.125$
$\displaystyle 2^{-2} = 0.25$
$\displaystyle 2^{-1} = 0.5$
$\displaystyle 3^{-3} = 0.037037$
$\displaystyle 3^{-2} = 0.111111$
$\displaystyle 3^{-1} = 0.333333$
$\displaystyle 4^{-3} = 0.015625$
$\displaystyle 4^{-2} = 0.0625$
$\displaystyle 4^{-1} = 0.25$
In [2]:
for i in range(0,10):
    for j in range(0,4):
        if i>0 and j>1:
            display(Math('%g^\\frac{1}{%g} = %g' %(i,j,i**(1/j))))
$\displaystyle 1^\frac{1}{2} = 1$
$\displaystyle 1^\frac{1}{3} = 1$
$\displaystyle 2^\frac{1}{2} = 1.41421$
$\displaystyle 2^\frac{1}{3} = 1.25992$
$\displaystyle 3^\frac{1}{2} = 1.73205$
$\displaystyle 3^\frac{1}{3} = 1.44225$
$\displaystyle 4^\frac{1}{2} = 2$
$\displaystyle 4^\frac{1}{3} = 1.5874$
$\displaystyle 5^\frac{1}{2} = 2.23607$
$\displaystyle 5^\frac{1}{3} = 1.70998$
$\displaystyle 6^\frac{1}{2} = 2.44949$
$\displaystyle 6^\frac{1}{3} = 1.81712$
$\displaystyle 7^\frac{1}{2} = 2.64575$
$\displaystyle 7^\frac{1}{3} = 1.91293$
$\displaystyle 8^\frac{1}{2} = 2.82843$
$\displaystyle 8^\frac{1}{3} = 2$
$\displaystyle 9^\frac{1}{2} = 3$
$\displaystyle 9^\frac{1}{3} = 2.08008$
In [3]:
def powers(x,y):
    display(Math('%g^{%g} = %g' %(x,y,x**y)))
In [4]:
def powersOfFractions(x,y):
    display(Math('%g^\\frac{1}{%g} = %g' %(x,y,x**(1/y))))
In [5]:
def calc():
    x = int (input('Input X: '))
    y = int (input('Input Y: '))
    
    display(Math('\\text{Press "1" to compute }%g^{%g}\\text{ or press "2" to compute }%g^\\frac{1}{%g}' %(x,y,x,y)))
    switch = input(' ')
    
    if switch=='1':
        powers(x,y)
    elif switch=='2':
        powersOfFractions(x,y)
    else:
        print('Invalid selection!')
In [6]:
calc()
Input X: 5
Input Y: 3
$\displaystyle \text{Press "1" to compute }5^{3}\text{ or press "2" to compute }5^\frac{1}{3}$
 1
$\displaystyle 5^{3} = 125$
In [7]:
calc()
Input X: 5
Input Y: 3
$\displaystyle \text{Press "1" to compute }5^{3}\text{ or press "2" to compute }5^\frac{1}{3}$
 2
$\displaystyle 5^\frac{1}{3} = 1.70998$