Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Erro: python boolean

def INSERTION_SORT(A):
    for j in range(len(A)-1):
        key = A[j]
        i = j+1
        print("***********")
        print(j >= 0)
        print(key > A[i])
        print(j >= 0 & key > A[i])

A = [5,2,4,6,1,3]

INSERTION_SORT(A)

operation result:

***********
True
True
False
***********
True
False
False
***********
True
False
False
***********
True
True
False
***********
True
False
False
[Finished in 52ms]

why are all true, the result is false

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

You should use and keyword instead of &

  • and: this is the logical and
  • &: this is the bitwise operator
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading