Hi Sebastian,

Very much thanks for your help.

Your explanation and illustrations is clear. I was not aware of that syntax.

I now understand and the issue is resolved.

Thanks again. Cheers.


-----Original Message-----
From: Sebastian Silva [mailto:sebast...@fuentelibre.org] 
Sent: Thursday, June 15, 2017 1:53 AM
To: William Gan <ganwill...@outlook.com>; tutor@python.org
Subject: Re: [Tutor] Fahrenheit to Celsius Conversion another problem and 
Programming Paradigm

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