Product SiteDocumentation Site

3.3.2. Temperature conversion

In this program we will convert the given temperature to Celsius from Fahrenheit by using the formula C=(F-32)/1.8
#!/usr/bin/env python
fahrenhite = 0.0
print "Fahrenheit Celsius"
while fahrenheit <= 250:
    celsius = ( fahrenheit - 32.0 ) / 1.8 #Here we calculate the fahrenhite value
    print "%5.1f %7.2f" % (fahrenheit , celsius)
    fahrenheit = fahrenheit + 25

The output
[kd@kdlappy book]$ ./temperature.py
Fahrenheit Celsius
  0.0  -17.78
 25.0   -3.89
 50.0   10.00
 75.0   23.89
100.0   37.78
125.0   51.67
150.0   65.56
175.0   79.44
200.0   93.33
225.0  107.22
250.0  121.11