Python Program to Convert Celsius To Fahrenheit

P

In this program, you’ll learn to convert Celsuis to Fahrenheit and display it.

To understand this example, you should have the knowledge of following Python programming topics:

  1. WHAT IS PYTHON? THINGS TO KNOW BEFORE CODE WITH PYTHON
  2. HOW DO I GET AND INSTALL PYTHON?
  3. PYTHON PRIMITIVES – VARIABLES, BUILT-IN DATA TYPES, COMMENTS, SYNTAX, AND SEMANTICS
  4. CODING APPROACHES IN PYTHON
  5. STYLE GUIDE FOR PROGRAMMING PYTHON CODE
  6. ERRORS AND EXCEPTIONS IN PYTHON

In the program below, we take temperature in degree Celsius and convert it into degree Fahrenheit. They are related by the formula:

celsius * 1.8 = fahrenheit – 32

Source Code

# Python Program to convert temperature in celsius to fahrenheit

# change this value for a different result
celsius = 37.5

# calculate fahrenheit
fahrenheit = (celsius * 1.8) + 32
print('%0.1f degree Celsius is equal to %0.1f degree Fahrenheit' %(celsius,fahrenheit))
Output

37.5 degree Celsius is equal to 99.5 degree Fahrenheit

To test, modify the above program to convert to convert Fahrenheit to Celsius using the following formula

celsius = (fahrenheit – 32) / 1.8

About the author

Pardeep Patel
Pardeep Patel

Add comment

Basics of Python