In this post, we will learn how to use Python to build a fahrenheit to celsius converter.
Fahrenheit and celsius are two of the most popular ways to measure temperature. However, the conversion between the two is not straightforward.
The formula for converting fahrenheit to celsius is:
BASH
celsius = (fahrenheit - 32) * 5 / 9
To start, let's ask the user for the temperature in fahrenheit. To do this, we will use the input function, then convert the input to a float so that we can perform arithmetic with it.
PYTHON
fahrenheit = float(input("Enter the temperature in Fahrenheit: "))
Now that we have the temperature in fahrenheit, we can convert it to celsius. Let's create a function using the above formula, and call it fahrenheit_to_celsius.