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 return elif statement

Discussão em 'Python' iniciado por Stack, Março 26, 2025.

  1. Stack

    Stack Membro Participativo

    Im trying to check is the number passed is a valid perfect square by

    return True if(math.sqrt(num)%2 == 0 or \
    (math.sqrt(num)+1) % 2 == 0 ) else False


    I want to know if I could write this better by breaking the if statement into two parts like

    return True if(math.sqrt(num)%2 == 0)
    elif ((math.sqrt(num)+1) % 2 == 0 )
    else False


    Could someone help me with how to use elif here or if there is a better approach.

    Thank you.

    Continue reading...

Compartilhe esta Página