Answer to Question #231923 in Python for umesh

Question #231923

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.




1
Expert's answer
2021-09-01T23:56:36-0400
t = input()
scale = t[-1]
t = float(t[:-1])
if scale == 'C':
    print(f'{round(t, 2)}C')
    print(f'{round(t * 9 / 5 + 32, 2)}F')
    print(f'{round(t + 273, 2)}K')
elif scale == 'K':
    print(f'{round(t - 273, 2)}C')
    print(f'{round((t - 273) * 9 / 5 + 32, 2)}F')
    print(f'{round(t, 2)}K')
elif scale == 'F':
    print(f'{round((t - 32) * 5 / 9, 2)}C')
    print(f'{round(t, 2)}F')
    print(f'{round((t - 32) * 5 / 9 + 273, 2)}K')

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
APPROVED BY CLIENTS