HOW to Implement Temperature Conversion In Python


In this example we will show how to complete a simple conversion between Celsius and Fahrenheit temperatures with Python.

Source Code

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

# Accept the temperature entered from the terminal and cast to floating point type
celsius = float(input('Enter Celsius temperature: '))

fahrenheit = (celsius * 1.8) + 32
print('Celsius temperature of %0.2f is Fahrenheit of %0.2f ' % (celsius, fahrenheit))

The results are as follows:

Enter Celsius temperature: 33
Celsius temperature of 33.00 is Fahrenheit of 91.40


Enter Celsius temperature: 45
Celsius temperature of 45.00 is Fahrenheit of 113.00
Subscribe
Notify of
guest
0 Comments
Inline Feedbacks
View all comments