Re: [Tutor] Fahrenheit to Celsius Conversion another problem and Programming Paradigm

2017-06-14 Thread Alex Kleider
On 2017-06-14 12:22, Mats Wichmann wrote: Of course if you do any serious argument handling, it's better to use something like optparse (and earlier argparse) module so you're not reinventing a wheel which has been massively worked on already. At the suggestion of a posting on this list some

Re: [Tutor] Fahrenheit to Celsius Conversion another problem and Programming Paradigm

2017-06-14 Thread Mats Wichmann
On 06/14/2017 12:18 PM, Sibylle Koczian wrote: > Correct usage would be: > > if myvar == val1 or myval == val2: > or > if myvar in (val1, val2): Just piling on here to say I find the second form very useful to collect arguments in a "friendly" way, if you don't have a reason to very rigidly

Re: [Tutor] Fahrenheit to Celsius Conversion another problem and Programming Paradigm

2017-06-14 Thread Peter Otten
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

Re: [Tutor] Fahrenheit to Celsius Conversion another problem and Programming Paradigm

2017-06-14 Thread Sibylle Koczian
Am 14.06.2017 um 16:20 schrieb William Gan: Good day Everyone, I am seeking help on two issues. ISSUE 1: Yesterday I posted a problem on this tiny script I wrote for temperature conversion (as practice for a newbie). My error was pointed out to me that there is a difference in upper and

Re: [Tutor] Fahrenheit to Celsius Conversion another problem and Programming Paradigm

2017-06-14 Thread Sebastian Silva
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

Re: [Tutor] Fahrenheit to Celsius Conversion another problem and Programming Paradigm

2017-06-14 Thread Alan Gauld via Tutor
On 14/06/17 15:20, William Gan wrote: > print('Enter C for Celsius to Fahrenheit or F for Fahrenheit to Celsius.') > > if unit == 'C' or 'c': You have hit a common error for beginners. reading this as a human it is quite clear what is meant but the computer sees it differently. It sees: if

Re: [Tutor] Fahrenheit to Celsius Conversion another problem and Programming Paradigm

2017-06-14 Thread David Rock
> On Jun 14, 2017, at 09:20, William Gan wrote: > > However, today I modified only the print instruction a little to try to print > out ℃ (in the second print clause). When I subsequently ran the script all > the outputs were executed from the if clause, even when I

[Tutor] Fahrenheit to Celsius Conversion another problem and Programming Paradigm

2017-06-14 Thread William Gan
Good day Everyone, I am seeking help on two issues. ISSUE 1: Yesterday I posted a problem on this tiny script I wrote for temperature conversion (as practice for a newbie). My error was pointed out to me that there is a difference in upper and lowercase letters. After correcting that error, I