Answer to Question #220130 in Python for Durga

Question #220130

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-07-25T08:25:11-0400

x = input("Enter Temperature:\t")



def calculateTemp(data):

convert = float(data[:-1])

sc = data[-1]

if(sc=="C" or sc=="c"):

print("{:.2f}C".format(convert))

print("{:.2f}F".format((convert * 9/5) + 32))

print("{:.2f}K".format(convert+273))

elif (sc=="F" or sc=="f"):

print("{:.2f}C".format((convert - 32) * 5/9))

print("{:.2f}F".format(convert))

print("{:.2f}K".format((convert - 32) * 5/9 + 273))

elif(sc=="K" or sc=="k"):

print("{:.2f}C".format(convert-273))

print("{:.2f}F".format((convert - 273) * 9/5 + 32))

print("{:.2f}K".format(convert))

calculateTemp(x)


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