[Tutor] Fahrenheit to Celsius Conversion another problem and Programming Paradigm
Peter Otten
__peter__ at web.de
Wed Jun 14 14:30:56 EDT 2017
Sebastian Silva wrote:
> Or shorter:
>
> if unit in 'Cc':
Don't do that. You are in for nasty surprises:
>>> def check(unit):
... if unit in "Cc":
... return "Celsius"
... return "unknown"
...
>>> check("c")
'Celsius'
>>> check("C")
'Celsius'
>>> check("F")
'unknown'
Fine so far. But now:
>>> check("Cc")
'Celsius'
>>> check("")
'Celsius'
More information about the Tutor
mailing list