How To Create A Python Celsius To Fahrenheit

Photo by Pontus Wellgraf on Unsplash

How to create a python program that converts Celsius Temperature to Fahrenheit Temperature

This is a Python 3 tutorial for creating a Celsius to Fahrenheit program, and in order to get started I always start with a comment about what the program that I am building is. By using the # key you are able to then create comments in Python.

# program that converts Celsius into Fahrenheit
# get users to input for Celsius then do some math to convert

After the comment, I would usually import the functions I would utilize within the program. In this program, I did not use a function, so I did not have to import anything for this program.

Next, I will greet the user with a print statement telling the user what the program does and after that, I will then get input from the user to input into the computer the high and low Celsius temperatures that they would like to convert into Fahrenheit.

print("Hello there this program will convert a high and low temperature for you.")
celsius1 = input("What is the high-temperature today in Celsius: ")
celsius2 = input("What is the low-temperature today in Celsius: ")

After I have gotten the user to input the temperatures, we will create 2 separate Fahrenheit variables that will calculate the temperatures into Fahrenheit. Remember to do a bit of research to get the correct formula to do this calculation, and the below code demonstrates that

fahrenheit1 = int(celsius1) * 9/5 + 32

Always ensure you are utilizing the correct formulas or the user will not get their desired outcomes. Logic errors can happen often. The program may run, but it does not output correctly, and sometimes logic errors can be hard to find if your outcome is not what it is supposed to be a good place to start especially, in this case, would be the formula used for the calculations.

No comments:

Post a Comment

Flag Quiz Game

Enjoy this free android app in the google play store. If you want to learn about the many country fl...