mardi 5 septembre 2017

Python comparison using if and print statement, output is incorrect when run using Spyder

listv1 = [6,10,12,14,30]
listc1 = [0.5,0.3,0.3,0.2,0.1]
listv2 = [6.1,9.2,12.3,14.7,30.8]
listc2 = [0.7, 0.5, 0.4, 0.33, 0.27, 0.18]
vdlist = []

newlistv1 = [float(i) for i in listv1]
newlistc1  = [float(i) for i in listc1]    
newlistv2  = [float(i) for i in listv2]
newlistc2  = [float(i) for i in listc2]

for i in range(0,len(newlistc1)):
    #print newlistv1[i]
    for j in range(0,len(newlistc2)):
        print newlistc1[i],newlistc2[i]
        if(1>2):
            print newlistc1[i],newlistc2[i]
        else:
            pass
            #print "passed"
            #pass
    #print newlistv2

Here, I am comparing two values ( 1 and 2 in the if statement) which is obviously false, but nevertheless goes on to execute the print statement insider if:

This is not executed when run in python console. What is the magic I am missing here > Why is the print statement inside if: executed even though it is False ?

Aucun commentaire:

Enregistrer un commentaire