Answer to Question #221293 in Python for Dr Kiran Tummalapa

Question #221293

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



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.

Sample Input 1

25C

Sample Output 1

25.0C

77.0F

298.0K




1
Expert's answer
2021-08-01T00:29:59-0400
temparature = input("Enter temparature: ")

unit = temparature[-1]
value = temparature[:-1]
if (unit == "C" or unit == "c"):
    celcius = float(value);
    print(round(celcius, 2), "C")
    print(round((celcius * 9 / 5) + 32, 2), "F")
    print(round(celcius + 273, 2), "K")
elif (unit == "F" or unit == "f"):
    fahr = float(value)
    print(round((fahr - 32) * 5 / 9, 2), "C")
    print(round(fahr, 2), "F")
    print(round((fahr - 32) * 5 / 9 + 273, 2), "K")
elif (unit == "K" or unit == "k"):
    kelv = float(value)
    print(round(kelv - 273, 2), "C")
    print(round((kelv - 273) * 9 / 5 + 32, 2), "F")
    print(round(kelv, 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
New on Blog
APPROVED BY CLIENTS