Objective
Develop a Python program that asks the user for a temperature in Celsius and converts it to both Kelvin and Fahrenheit. Use the following formulas for conversion:
Kelvin = Celsius + 273
Fahrenheit = Celsius * 1.8 + 32
The program should then display the temperature in both Kelvin and Fahrenheit.
Example Python Exercise
Show Python Code
# Prompt the user to enter a temperature in Celsius
celsius = float(input("Please enter a temperature in Celsius: "))
# Convert the temperature to Kelvin
kelvin = celsius + 273
# Convert the temperature to Fahrenheit
fahrenheit = celsius * 1.8 + 32
# Display the temperature in both Kelvin and Fahrenheit
print(f"The temperature in Kelvin is {kelvin}")
print(f"The temperature in Fahrenheit is {fahrenheit}")
Output
Please enter a temperature in Celsius: 25
The temperature in Kelvin is 298.0
The temperature in Fahrenheit is 77.0
Share this Python Exercise