# Write a Python program to convert temperature from Celsius t…

Write a Python program to convert temperature from Celsius to Fahrenheit and Kelvins; from Fahrenheit to Celsius and Kelvins. Document your program – to include your name, course, date written, and the formulas used in the conversions. Instruct the user on how to enter the data requested.

Name: John Smith
Course: Computer Science 101
Date: October 15, 2021

Python Program to Convert Temperature

Introduction:
This program is designed to convert temperature values between Celsius, Fahrenheit, and Kelvin scales. It takes user input for the initial temperature in a specific scale and converts it to the desired scale. The program utilizes the formulas for temperature conversion to perform the calculations.

Formulas used in the conversions:

1. Celsius to Fahrenheit:
F = (C * 9/5) + 32

2. Celsius to Kelvin:
K = C + 273.15

3. Fahrenheit to Celsius:
C = (F – 32) * 5/9

4. Fahrenheit to Kelvin:
K = (F + 459.67) * 5/9

Instructions for using the program:
1. Run the program in a Python interpreter or IDE.
2. The program will prompt you to enter the initial temperature value and the scale in which it is measured (Celsius or Fahrenheit).
3. Enter the temperature value as a numeric value without any units. For example, if the initial temperature is 25 degrees Celsius, enter “25”.
4. Enter the scale of the initial temperature as either “C” for Celsius or “F” for Fahrenheit.

Python program for temperature conversion:

“`python
def celsius_to_fahrenheit(celsius):
fahrenheit = (celsius * 9/5) + 32
return fahrenheit

def celsius_to_kelvin(celsius):
kelvin = celsius + 273.15
return kelvin

def fahrenheit_to_celsius(fahrenheit):
celsius = (fahrenheit – 32) * 5/9
return celsius

def fahrenheit_to_kelvin(fahrenheit):
kelvin = (fahrenheit + 459.67) * 5/9
return kelvin

# Prompt user for temperature value and scale
temperature = float(input(“Enter the temperature value: “))
scale = input(“Enter the temperature scale (C for Celsius, F for Fahrenheit): “)

# Perform temperature conversions based on user’s input
if scale.upper() == ‘C’:
fahrenheit = celsius_to_fahrenheit(temperature)
kelvin = celsius_to_kelvin(temperature)
print(f”{temperature} degrees Celsius is equal to {fahrenheit} degrees Fahrenheit and {kelvin} Kelvins.”)
elif scale.upper() == ‘F’:
celsius = fahrenheit_to_celsius(temperature)
kelvin = fahrenheit_to_kelvin(temperature)
print(f”{temperature} degrees Fahrenheit is equal to {celsius} degrees Celsius and {kelvin} Kelvins.”)
else:
print(“Invalid input. Please enter either C or F for the temperature scale.”)
“`

In this program, we have defined four functions for the different temperature conversions: celsius_to_fahrenheit, celsius_to_kelvin, fahrenheit_to_celsius, and fahrenheit_to_kelvin. These functions take one parameter, the initial temperature value, and return the converted temperature value. The main part of the program prompts the user for the temperature value and scale, calls the appropriate conversion functions based on the user’s input, and prints the converted temperature values.

Conclusion:
This program provides a convenient way to convert temperature values between Celsius, Fahrenheit, and Kelvin scales. By following the instructions and entering the required data, users can accurately convert temperatures using the provided formulas.

The post Write a Python program to convert temperature from Celsius t… appeared first on My Perfect Tutors.

## "Is this question part of your assignment? We Can Help!" 