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

Popular posts from this blog

how to insert data php javascript mysql with multiple array session 2 -

multithreading - Exception in Application constructor -

windows - CertCreateCertificateContext returns CRYPT_E_ASN1_BADTAG / 8009310b -