Python program to convert the temperature in degree centigrade to Fahrenheit

12/24/2021
All Articles

#Python #program to convert the temperature in degree centigrade to Fahrenheit #question #celsius to fahrenheit python program

Python program to convert the temperature in degree centigrade to Fahrenheit

Python Program to Convert Celsius to Fahrenheit

Introduction

Temperature conversion is a common mathematical calculation in various applications. In this article, we will learn how to convert a temperature from degrees Celsius to Fahrenheit using Python. This is a simple yet important program often asked in coding interviews and beginner-level programming exercises.

Formula for Celsius to Fahrenheit Conversion

To convert temperature from Celsius to Fahrenheit, we use the following formula:

Fahrenheit = (1.8 * Celsius) + 32

Where:

  • Celsius is the temperature in degrees centigrade.
  • Fahrenheit is the temperature in Fahrenheit scale.

Python Code for Temperature Conversion

Below is a Python program that takes user input for temperature in Celsius and converts it to Fahrenheit:

# Python program to convert Celsius to Fahrenheit
c = input("Enter temperature in Celsius: ")

# Convert the input to float and apply the formula
f = (9 * float(c) / 5) + 32

# Display the result
print(f"Temperature in Fahrenheit is: {f:.2f} ")

Example

Input:

37

Output:

37.00 Celsius is: 98.60 Fahrenheit

Explanation of the Code

  1. The program takes user input for the temperature in Celsius.
  2. It converts the input into a floating-point number for accurate calculations.
  3. It applies the conversion formula to compute the Fahrenheit equivalent.
  4. The output is displayed with two decimal precision for clarity.

Key Features of This Program

  • Accepts dynamic input from the user.
  • Converts temperature using the standard formula.
  • Displays the output in a user-friendly format.
  • Works efficiently with all valid numerical inputs.

Conclusion

This Python program allows users to easily convert temperature from Celsius to Fahrenheit. By understanding and implementing this simple logic, you can expand the program to perform more complex temperature conversions, such as Fahrenheit to Celsius or Kelvin conversions. Try modifying the code to include other temperature scales and enhance your Python skills!

Article