Python Program to convert Fahrenheit to Celsius

Program

# Python Program to convert temperature in fahrenheit to celsius
fahrenheitVal = float(input('Enter a Fahrenheit value you want to convert: '))
# calculate celsius using the formula
# celsius * 1.8 = fahrenheit - 32
celsius = (fahrenheitVal - 32)/1.8
print('%0.1f degree Fahrenheit = %0.1f degree celsius' %(fahrenheitVal,celsius))

This program converts a temperature in Fahrenheit to Celsius using a simple mathematical formula.

  1. Take User Input

    • The user enters a temperature in Fahrenheit as a floating-point number.
  2. Convert to Celsius

    • The program applies the formula:
      [
      \text{Celsius} = \frac{(\text{Fahrenheit} - 32)}{1.8} ]
    • This formula converts Fahrenheit to Celsius.
  3. Display Output

    • The result is printed with one decimal place using '%0.1f'.

Key Takeaways

  • The formula (F - 32) / 1.8 is used for conversion.
  • The program supports decimal values as input.
  • The output is formatted to one decimal place for better readability.

Output

$ python3 ConvertFahrenheitToCelsius.py 
Enter a Fahrenheit value you want to convert: 99.5
99.5 degree Fahrenheit = 37.5 degree celsius