Temperature Conversion Program
Aim: To write a Python program to convert temperature to and from Celsius to Fahrenheit.
Algorithm:
1. Define a function `celsius_to_fahrenheit` to convert Celsius to Fahrenheit using the formula: (C *
9/5) + 32.
2. Define a function `fahrenheit_to_celsius` to convert Fahrenheit to Celsius using the formula: (F -
32) * 5/9.
3. Take input for temperature in Celsius and call the `celsius_to_fahrenheit` function.
4. Display the result in Fahrenheit.
5. Take input for temperature in Fahrenheit and call the `fahrenheit_to_celsius` function.
6. Display the result in Celsius.
Program:
def celsius_to_fahrenheit(celsius):
return (celsius * 9/5) + 32
def fahrenheit_to_celsius(fahrenheit):
return (fahrenheit - 32) * 5/9
celsius = float(input("Enter temperature in Celsius: "))
fahrenheit = celsius_to_fahrenheit(celsius)
print("Temperature in Fahrenheit:", fahrenheit)
fahrenheit = float(input("Enter temperature in Fahrenheit: "))
celsius = fahrenheit_to_celsius(fahrenheit)
print("Temperature in Celsius:", celsius)
Output:
Enter temperature in Celsius: 0
Temperature in Fahrenheit: 32.0
Enter temperature in Fahrenheit: 32
Temperature in Celsius: 0.0