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

William Gan ganwilliam at outlook.com
Wed Jun 14 10:20:56 EDT 2017


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 remember the tests I ran produced the correct outputs.


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 input other letters (Please see below. I have removed the code to print degree C).



print('Enter C for Celsius to Fahrenheit or F for Fahrenheit to Celsius.')

unit = input('Enter C or F: ')

temp = int(input('Enter temperature: '))



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

    f = temp * 9 / 5 + 32

    print(str(temp) + ' C is equivalent to ' + '%.2f' % f + ' F.')

elif unit == 'F' or 'f':

    c = (temp - 32) * 5 / 9

    print(str(temp) + ' F is equivalent to ' + "%.2f" % c + ' C.')

else:

    print('Please enter C or F in upper- or lowercase.')



The if statement block is to convert Celsius to Fahrenheit.

When I entered ‘C’ or ‘c’ and 100 for temperature, the output is correct: 100 C is equivalent to 212.00 F.



The elif statement block is to convert Fahrenheit to Celsius.

When I entered ‘f’ or another letter, in this case ‘z’ and ‘g’, and 212 for temperature, I got: 212 C is equivalent to 413.60 F.



I have looked at it many times today and could not see the error. Please advise.



ISSUE 2:

The second issue relates to the last statement above “I have looked at it many times today and could not see the error”.



I was hoping that someone, perhaps one with pedagogical experience and knowledge, could advise the following:

1.       Is it possible that I may not have the right aptitude or mental paradigm to do computer programming?

I think I don’t. My background is in finance, accounting and economics. When I have difficulty in certain concepts in these fields I could figure it out eventually, in reasonable time.

However, I am having difficulty learning it. I have been learning for a few months already and I am not learning fast enough.

2.       Nevertheless, I intend to keep learning and practicing, but wonder if there is an effective way to get a breakthrough into the programming paradigm? If so, kindly advise how and direct me to a suitable resource to do it.



Many thanks.



Best regards.


More information about the Tutor mailing list