Software & Finance





Python - Fahrenheit to Celsius Conversion





 

I have given here python program for Fahrenheit to Celsius conversion and Celsius to Fahrenheit conversion. This code is tested with Python version 2.6

 

        val = 0.0
        Celsius = 0.0
        Fahrenheit = 0.0
        
        print "Enter a number to use in Fahrenheit and Celsius Converter: ",
        val = input()
        
        Celsius = (val - 32.0) * 5.0 / 9.0;
        Fahrenheit = (val * (9.0 / 5.0) + 32);
         
        print "%.4lf" %val, chr(248), "F = %.4lf" %Celsius, chr(248), "C";
        print "%.4lf" %val, chr(248), "C = %.4lf" %Fahrenheit, chr(248), "F";
        
        #sample output
        #Enter a number to use in Fahrenheit and Celsius Converter:  98.4
        #98.4000 ° F = 36.8889 ° C
        #98.4000 ° C = 209.1200 ° F

        #Enter a number to use in Fahrenheit and Celsius Converter:  -40
        #-40.0000 ° F = -40.0000 ° C
        #-40.0000 ° C = -40.0000 ° F