[Fixed]-Python if elif else only returning first output without using logic

1👍

If you say feat_list() < 12 dand the value is 11.5, then its true, and execute the firt if, but the next condition will be also true 11 < feat_list() <= 15,
because 11.5, is between 11 and 15.
My point is… your first condition in your first if, is “containded” in the second condition of the elif:

12 is between 11 and 15, because 11 < 12 <= 15, so, the first condition is wrong.

0👍

the elif will only be evaluated when the if was not true.

So, if you want to check for 11 < feat_list() <= 15: even if feat_list() < 12: is true, use if instead of elif

👤micchr

0👍

In your example, the comparison ranges overlap between Silver and Gold packages (11-12). Also, you probably don’t want the Platinum package to be the “default” one (without check, provided it is the highest level). Maybe it would be more clear what the code is doing if you rewrote the comparison in the following style (pseudocode):

flist = feat_list()
# You can check the returned value here, ie. print(flist), and the value
# won't change before you're finished with the comparison.

if flist > 15:
    #...Platinum processing...
elif flist > 11:
    #...Gold processing...
else:
    #...Silver processing...

Leave a comment