You are given the temperature T of an object in one of Celsius, Fahrenheit, and Kelvin scales.
Write a program to print T in all scales viz Celsius, Fahrenheit, and Kelvin.
Formula to convert from Fahrenheit F to Celsius C is C = (F - 32) * 5 / 9.
Formula to convert from Kelvin K to Celsius C is C = K - 273.
Here "C", "F", "K" represent that the temperature scale is in Celsius, Fahrenheit and Kelvin scales respectively.
The input contains the temperature (a number) and the unit of the temperature scale (C, F, K) without any space.
Input
The first line of the input contain a temperature Value in one of Celsius, Fahrenheit, and Kelvin scales.
s = input("Enter the temperature : ")
try:
x = int(s[:-1])
if s[-1].lower() == 'k':
C = x - 273
K = x
F = (9 / 5) * C + 32
print("Temperature in Celcius:", C, " C")
print("Temperature in Kelvin:", K, " K")
print("Temperature in Fahrenheit", F, " F")
elif s[-1].lower() == 'c':
C = x
K = C + 273
F = (9 / 5) * C + 3
print("Temperature in Celcius:", C, " C")
print("Temperature in Kelvin:", K, " K")
print("Temperature in Fahrenheit", F, " F")
elif s[-1].lower() == 'f':
C = (x - 32) * 5 / 9
K = C + 273
F = x
print("Temperature in Celcius:", C, " C")
print("Temperature in Kelvin:", K, " K")
print("Temperature in Fahrenheit", F, " F")
else:
print('Invalid input')
except ValueError:
print('Invalid input')
Comments
Leave a comment