Fahrenheit to Celsius Converter in Python

Python Code

# Function to convert Fahrenheit to Celsius
def fahrenheit_to_celsius(fahrenheit):
    return (fahrenheit - 32) * 5.0 / 9.0

# Main program
def main():
    # Get user input
    fahrenheit = float(input("Enter temperature in Fahrenheit: "))
    
    # Convert to Celsius
    celsius = fahrenheit_to_celsius(fahrenheit)
    
    # Display the result
    print(f"{fahrenheit}°F is equal to {celsius:.2f}°C")

# Run the program
if __name__ == "__main__":
    main()
    

How to Run the Program

  1. Copy the Code: Copy the code above into a text editor or an Integrated Development Environment (IDE) like PyCharm or Visual Studio Code.
  2. Save the File: Save the file with a .py extension, for example, fahrenheit_to_celsius.py.
  3. Run the Program:
  4. Input Temperature: When prompted, enter a temperature in Fahrenheit, and the program will display the equivalent temperature in Celsius.

Example Output

Enter temperature in Fahrenheit: 100
100.0°F is equal to 37.78°C