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.
The output contains temperature in Celsius, Fahrenheit and Kelvin scales in each line in the format similar to input and the value of the temperature is rounded to 2 decimal places.Input
The first line of the input contain a temperature Value in one of Celsius, Fahrenheit, and Kelvin scales.Output
The first line of output should contain the Celsius value and the unit of the Celsius without any space.
The second line of output should contain the Fahrenheit value and the unit of the Fahrenheit without any space.
The third line of output should contain the Kelvin value and the unit of the Kelvin without any space.Explanation
For example, if the given temperature Value is 25C then Celsius value is 25.0C, Fahrenheit value is 77.0F, and Kelvin value is 298.0K.
i = input("Enter the temperature : ")
# if temperature is in kelvin
if i[-1] == "k" or i[-1] == "K":
x = int(i[:-1])
c = x - 273
k = x
f = (9*c/5) + 32
print("Temperature in Celcius is :",c," C")
print("Temperature in Kelvin is :",k," K")
print("Temperature in Fahrenheit is :",f," F")
# if temperature is in celcius
if i[-1] == "c" or i[-1] == "C":
x = int(i[:-1])
c = x
k = x + 273
f = (9*c/5) + 32
print("Temperature in Celcius is :",c," C")
print("Temperature in Kelvin is :",k," K")
print("Temperature in Fahrenheit is :",f," F")
# if temperature is in fahrenheit
if i[-1] == "f" or i[-1] == "F":
x = int(i[:-1])
c = (x-32)*5/9
k = c + 273
f = x
print("Temperature in Celcius is :",c," C")
print("Temperature in Kelvin is :",k," K")
print("Temperature in Fahrenheit is :",f," F")
Comments
Leave a comment