1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.
  2. Anuncie Aqui
    Anuncie aqui você Também: fdantas@4each.com.br

[Python] python, square root simplification function

Discussão em 'Python' iniciado por Stack, Setembro 25, 2024.

  1. Stack

    Stack Membro Participativo

    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,")")

    Continue reading...

Compartilhe esta Página