Answer to Question #167850 in Python for prathyusha

Question #167850

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.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.

Sample Input 1

25C

Sample Output 1

25.0C

77.0F

298.0K

Sample Input 2

37.5F

Sample Output 2

3.06C

37.5F

276.06K


1
Expert's answer
2021-03-02T15:32:50-0500
#Get values from the user
values=input("")
#get temperature
temperature=float(values[0:-1])
#get scale
scale=values[-1]
Celsius=temperature
Fahrenheit=temperature
Kelvin=temperature
isValidData=True
if scale.upper()=='C':
    #Calculate Kelvin temperature
    Kelvin=Celsius+273.15
    #Calculate Fahrenheit temperature
    Fahrenheit=(Celsius * 1.8) + 32  
elif scale.upper()=='F':        
    #Calculate Kelvin temperature
    Kelvin=(Fahrenheit - 32) * 5/9 + 273.15
    #Calculate Celsius temperature
    Celsius=(Fahrenheit - 32) * 5.0 / 9.0
elif scale.upper()=='K':
    #Calculate Fahrenheit temperature
    Fahrenheit=(Kelvin - 273.15) * 9/5 + 32
    #Calculate Celsius temperature
    Celsius= Kelvin - 273.15
else:
    print("\nWrong input data!\n")
    isValidData=False
if isValidData:
    #Display result
    print("{:.2f}C".format(Celsius))
    print("{:.2f}F".format(Fahrenheit))
    print("{:.2f}K".format(Kelvin))

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