In: Computer Science
write a python function that takes a number as input argument, and that tries to determine two other integers, root and pwr, such that root**pwr is equal to the integer passed as an argument to the function. Consider that pwr > 1. The function should return the values of root and pwr, as a string in the form root**pwr. For example, when the passed argument is 8, the function should return the string ‘2**3’. When the passed input argument does not have a root**pwr representation, the function should return the value None. Write a “docstring” for the function specifying its input parameter, its assumption and the return value that the user should expect. Write a small program that requests the user to enter several numbers, and then, for each, calls the function to determine the power representation if it exists, and finally to print this representation or, if no such representation exists, to write some suitable message. Select a proper sentinel for the user to enter in order to stop the program. Make sure you inform the user of the type of sentinel that you select.
Please find the answer below.
''' Enter an integer then if the number can be represennted in a
form of root and power then
power() function should return the values of root and pwr, as a
string in the form root**pwr.
else the function will rerun a message '''
import math
c='y'
while (c=='y'):
number=int(input("Enter a number : "))
flag=0
def power():
for i in range (1,50):
for j in range (2,51):
if (number==math.pow(i,j)):
flag=1
return (str(i)+"**"+str(j))
else:
flag=0
if (flag==0):
return (str(number)+" can not be represented with any root and
power !")
print(power())
c=input("Presss 'y' to continue 'n' to exit ... ")
OUTPUT :