Tuesday, 15 April 2014

python - If/Elif/Else statement issue. If if and elif not met, not going into else -



python - If/Elif/Else statement issue. If if and elif not met, not going into else -

sorry extremely obvious question, i've been having problem if/elif/else statement. statement never proceeds "else" area. if difference equal 0.

if difference > 0: difference_string = "the combination have %s cm gap beingness enclosed." % (difference) elif difference < 0: difference_string = "the combination exceed dimensions of shelf unit %s cm." % (difference) else: difference_string = "the combination enclose %s cm shelf unit." % (uh)

i don't what's not right. guess elif == 0, want understand error before work on fixing it.

here whole code:

def x38door_fit(uh): """uh = unit height door_fit(uh) --> x*38 door heights fit on uh. """ uh = int(uh) doors = uh / int(38) if uh % int(38) not 0: tuh = 0 counter = 0 d38 = int(38) while tuh < uh: d38 += 38 tuh = d38 counter += 1 tdh = counter * 38 #total door height = tdh difference = uh - tdh if difference > 0: difference_string = "the combination have %s cm gap beingness enclosed." % (difference) elif difference < 0: difference_string = "the combination exceed dimensions of shelf unit %s cm." % (difference) else: difference_string = "the combination enclose %s cm shelf unit." % (uh) print difference_string print doors homecoming doors

your problem line of code:

if uh % int(38) not 0:

if pass in 0, assigned uh, conditional evaluates 0. if/else block in question never executed because never reached.

python if-statement

No comments:

Post a Comment