samedi 22 août 2015

Python: if statement condition isnt satisfied but still program works

I have a simple code

 def func(a,b):
    if (b>=3.0) and (b<=4.0):
        if (a>=3.0) and (a<=6.0):
            var_region='A'
        if (a>6.0) and (a<=11.0):
            var_region='B'
    if (b>4.0):
        var_region='C'

    region=var_region
    print region
    return region


Tmax=4.1
Tmin=3.0
T=Tmin
var=3.0
dT=0.1
while T<Tmax:
    calll=func(var,T)
    T=T+dT

The output of the program is:

A,A..........,C

In while loop, the final value of "T" is 4.0, and it prints "C" instead of "A". why is that? Thank you

Aucun commentaire:

Enregistrer un commentaire