I’ve flags, each range of value has a flag.
for ex :
- value = 0 is D
- value > 0 and < 0.2 is C
- value >=0.2 and <=0.8 is B
- value > 0.8 is A
flag = ["A", "B", "C", "D"]
def get_flag(value) :
if value == 0: return "D"
elif value > 0.8: return "A"
elif value <=0.8 and value >= 0.2: return "B"
else: return "C"
i think this implementation is annoying and not algorthmically pretty to see, any suggestions so i can get the correct index in python, i thought about modulo and div but values are floats between 0 and 1.
>Solution :
You don’t need elif and else here, since return ends the execution of the function (so that lines after a return are not executed if the preceding return is triggered):
def get_flag(value) :
if value == 0: return "D"
if value < 0.2: return "C"
if value <= 0.8: return "B"
return "A"