Python 2.7 if / elif statement with or -
i'm new python i'm sure i'm doing wrong. defining function accepts string variable. can not sure variable be, there 3 values want test , return string if values found. if values not found, want return 'unknown'. here code:
def item_priority(cell_color): if cell_color == 'green' or 'yellow': return 'low' elif cell_color == 'red': return 'high' else: return 'unknown' so try execute:
>> item_priority('orange') python returns:
'low' the result expected see 'unknown'. if test "item_priority('red')", still returns 'low'. explanations have found on site far involve code more complex mine.
i have tried interchanging second 'if' 'elif' result still same. i'm not sure i'm doing wrong here. appreciated. thanks!
'yellow' evaluating true within if-conditional, therefore block of code being executed whatever pass in. need add or cell_color == 'yellow' line 2
Comments
Post a Comment