Hi William,

Glad to see the tutor list is being of help in your learning.


On 14/06/17 09:20, William Gan wrote:
> if unit == 'C' or 'c':

In this case, it will always be true, because there are two conditions,
either:

  *  unit == 'C' or
  * 'c'

As you can see, the second condition is not a comparison, but a string
expression, that Python always evaluates to True (except for '' empty
string).

Thus, the combined condition is always true because the second
expression is always True.

The correct condition would be:

    if unit=='C' or unit=='c':

Or perhaps more clear, also correct:

    if unit in ('C', 'c'):

Or shorter:

    if unit in 'Cc':

Hope it's useful,

Regards,

Sebastian


_______________________________________________
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor

Reply via email to