I'm trying to make a function in python that will simplify the number into an integer under the root. For example:
- √(27) = 3 √(3)
- √(567) = 9 √(7)
I have written the following function, but it's working partially, as I think the while loop isn't effective. Any help please?
def sqrt2(num):
numbers=[]
roots=[]
#i=1-11
while num>1:
for i in range(1,num+1):
if num%i==0:
num=num//i
if num%i==0:
num=num//i
numbers.append(i)
else:
roots.append(i)
break
result=1
for i in numbers:
result= result*i
u_root=1
for j in roots:
u_root=u_root*j
print (result,"sqrt (",u_root,")")