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] Any way to extract the sign of a number in Python?

Discussão em 'Python' iniciado por Stack, Setembro 17, 2025.

  1. Stack

    Stack Membro Participativo

    I have am coding the algorithm of Bolzano in Python. This is my code for now:

    def Bolzano(fonction, a, b, tol=0.000001):
    while abs(b-a)>tol:
    m=(a+b)/2
    if cmp(fonction(m))==cmp(fonction(a)):
    a=m
    else:
    b=m
    return a, b


    It works until it encounters cmp, which it doesn't recognise. However I don't see another way to do it, since Python doesn't have a sign function. Is there any other way to extract the sign of a number?

    Continue reading...

Compartilhe esta Página