DEV Community

Cover image for How to build an Fahrenheit to Celsius Converter in Python
Rishabh Singh ⚡
Rishabh Singh ⚡

Posted on

How to build an Fahrenheit to Celsius Converter in Python

Hey everyone, today we will be building a Fahrenheit to Celsius Converter in Python.

How does it work?

Alt Text

Generally to measure the temperature we make use of one of these two popular units i.e. Fahrenheit & Celsius.

Converting one into another is usually boring and can be easily automated. Today we will be building a simple & short project which will convert Fahrenheit to Celsius for us in seconds.

Let's Code

So the first thing we are going to do is to ask the user for the temperature in Fahrenheit to convert it into the Celsius.

temp = float(input("Enter temperature in Fahrenheit: "))
Enter fullscreen mode Exit fullscreen mode

We will convert the temperature into float using float() so that we can perform calculations on it.

Now finally let's perform calculation and convert the temperature into Celsius.

celsius = (temp - 32) * 5/9
Enter fullscreen mode Exit fullscreen mode

This expression you see above is the general formula to convert Fahrenheit into Celsius.

Now finally let's print our temperature in Celsius:

print(f"{temp} in Fahrenheit is equal to {celsius} in Celsius")
Enter fullscreen mode Exit fullscreen mode

Here we go we are done! Here we have used f-strings to directly place the variable within the print statement.

Source Code

You can find the complete source code of this project here -

mindninjaX/Python-Projects-for-Beginners

Support

Thank you so much for reading! I hope you found this beginner project useful.

If you like my work please consider Buying me a Coffee so that I can bring more projects, more articles for you.

https://dev-to-uploads.s3.amazonaws.com/i/5irx7eny4412etlwnc64.png

Also if you have any questions or doubts feel free to contact me on Twitter, LinkedIn & GitHub. Or you can also post a comment/discussion & I will try my best to help you :D

Top comments (0)