How to Convert Celsius Unit into Fahrenheit in Python


This example will teach us how to make a convert from Celsius unit of temperature into its Fahrenheit unit in Python.

Source Code

#! /usr/bin/env python3
# -*- coding: utf-8 -*-

#Convert from Celsuis to Fahrenheit
c = float(input("Enter the Celsius temperature: "))
f = (c * 9 / 5) + 32
print("The Fahrenheit temperature is: ", f)

#Convert from Fahrenheit to Celsuis
f = float(input("Enter the Fahrenheit temperature: "))
c = (f - 32) * 5 / 9
print("The Celsius temperature is: ", c)

Output:

Enter the Celsius temperature: 40
The Fahrenheit temperature is:  104.0
Enter the Fahrenheit temperature: 104
The Celsius temperature is:  40.0

Enter the Celsius temperature: 56
The Fahrenheit temperature is:  132.8
Enter the Fahrenheit temperature: 132.8
The Celsius temperature is:  56.00000000000001
Subscribe
Notify of
guest
0 Comments
Inline Feedbacks
View all comments
Advertisement