Python: Celsius to Fahrenheit

1. Introduction

Temperature conversion is a common task when dealing with various scientific computations or even in daily life scenarios when traveling to countries that use different temperature scales. The Celsius and Fahrenheit scales are the two most commonly used temperature scales globally. In this blog post, we will create a Python program to convert temperatures from Celsius to Fahrenheit.

2. Program Overview

The program will:

1. Prompt the user to enter a temperature in Celsius.

2. Convert the given temperature from Celsius to Fahrenheit.

3. Display the converted temperature to the user.

3. Code Program

# Taking temperature in Celsius as input
celsius = float(input("Enter temperature in Celsius: "))

# Converting Celsius to Fahrenheit
fahrenheit = (celsius * 9/5) + 32

# Displaying the converted temperature
print(f"{celsius} Celsius is equal to {fahrenheit} Fahrenheit.")

Output:

Enter temperature in Celsius: 25
25.0 Celsius is equal to 77.0 Fahrenheit.

4. Step By Step Explanation

1. The program begins by taking the temperature in Celsius from the user. We use the input function to collect this data, which returns a string. To perform arithmetic operations, we then convert this string to a floating-point number using the float function.

2. We then use the standard formula to convert Celsius to Fahrenheit. Multiplying the Celsius temperature by 9/5 gives us a value, to which we then add 32 to get the temperature in Fahrenheit.

3. Finally, the print function is used to display the original temperature in Celsius and its equivalent in Fahrenheit.

This program provides a clear example of how Python can be used for quick and efficient mathematical calculations, such as unit conversions.

Comments