Python Program to Convert Celsius to Fahrenheit

Problem Description

Write a Python program that takes the temperature in Celsius and converts it to Fahrenheit.

What is Celsius?
Celsius is a unit used to measure temperature on the Celsius scale. It is named after the Swedish astronomer Anders Celsius and is commonly represented by the symbol °C(degree Celsius).

What is Celsius scale?
The Celsius scale is based on the freezing and boiling points of water at 1 atm pressure, which are assigned values of 0°C and 100°C, respectively. The scale is divided into 100 units between these two reference points, often referred to as the centigrade scale.

What is Fahrenheit?
Fahrenheit is a unit used to measure temperature on the Fahrenheit scale. It was developed by polish physicist Daniel Gabriel Fahrenheit in 1724 and is often denoted by symbol °F(degree Fahrenheit).

What is Fahrenheit scale?
On Fahrenheit scale the freezing and boiling point of water is defined at 32° and 212°F respectively with 180 divisions between them.

Problem Solution

Celsius to Fahrenheit conversion in Python:
To convert Celsius to Fahrenheit in Python, you can use the following formula:

Fahrenheit = (Celsius * 9/5) + 32

Example: Given, Celsius = 32
Fahrenheit = (Celsius * 9/5) + 32
Fahrenheit = (32*9/5) + 32 = 57.6 + 32 = 89.6

Program/Source Code

Here is source code of the Python Program to take the temperature in Celsius and convert it to Fahrenheit. The program output is also shown below.

Sanfoundry Certification Contest of the Month is Live. 100+ Subjects. Participate Now!
celsius=int(input("Enter the temperature in celcius:"))
print("Temperature in farenheit is:",f)
Program Explanation

1. User must first enter the value of temperature in Celsius.
2. Using the formula of: f=(c*1.8)+32, convert Celsius to Fahrenheit.
3. Print the temperature in Fahrenheit.

Time Complexity: O(1)
The time complexity of the given code is constant or O(1) because the operations performed (input, multiplication, addition, and print) have fixed execution times regardless of the input size.

Space Complexity: O(1)
The space complexity is also constanti.e. O(1) as it does not use any additional data structures that depend on the input size.

Runtime Test Cases

Testcase 1: In this case, we’re entering “32” as the Celsius value to convert to Fahrenheit.

Enter the temperature in celcius:32
Temperature in Fahrenheit is: 89.6

Testcase 2: In this case, we’re entering “48” as the Celsius value to convert to Fahrenheit.

Enter the temperature in celcius:48
Temperature in Fahrenheit is: 118.4

To practice programs on every topic in Python, please visit “Programming Examples in Python”.


Subscribe to our Newsletters (Subject-wise). Participate in the Sanfoundry Certification contest to get free Certificate of Merit. Join our social networks below and stay updated with latest contests, videos, internships and jobs!

Youtube | Telegram | LinkedIn | Instagram | Facebook | Twitter | Pinterest
Manish Bhojasia - Founder & CTO at Sanfoundry
Manish Bhojasia, a technology veteran with 20+ years @ Cisco & Wipro, is Founder and CTO at Sanfoundry. He lives in Bangalore, and focuses on development of Linux Kernel, SAN Technologies, Advanced C, Data Structures & Alogrithms. Stay connected with him at LinkedIn.

Subscribe to his free Masterclasses at Youtube & discussions at Telegram SanfoundryClasses.