Temperature Conversion
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.
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.
string1 = input('Enter temperature here:')
num = float(string1[:-1])
if string1[-1] == 'C':
num1 = (1.8*num)+32
num2 = num+273
print(str(num)+'C')
print(str(num1) + 'F')
print(str(num2) + 'K')
if string1[-1] == 'K':
num1 = num-273
num2 = 1.8*(num-273)+32
print(str(num)+'K')
print(str(num1) + 'C')
print(str(num2) + 'F')
if string1[-1] == 'F':
num1 = ((5/9)*(num-32))+273
num2 = (5/9)*(num-32)
print(str(num)+'F')
print(str(num1) + 'K')
print(str(num2) + 'C')
Enter temperature here:25C
25.0C
77.0F
298.0K
Enter temperature here:-40F
-40.0F
233.0K
-40.0C
Enter temperature here:373K
373.0K
100.0C
212.0F
Comments
Leave a comment