Python Celsius To Fahrenheit




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

This is a Python 3 tutorials 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 then import the functions that 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 then 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




Remember to 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 but 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

Best Devices To Get Started With Programming

Having a good solid computer is vital to start coding, and HP offers solid laptops for coders at every level.