Answer to Question #194954 in Python for divyaswini

Question #194954

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.

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




1
Expert's answer
2021-05-18T14:06:39-0400
s = input("Enter the temperature : ")
try:
    x = int(s[:-1])
    if s[-1].lower() == 'k':
        C = x - 273
        K = x
        F = (9 / 5) * C + 32
        print("Temperature in Celcius:", C, " C")
        print("Temperature in Kelvin:", K, " K")
        print("Temperature in Fahrenheit", F, " F")
    elif s[-1].lower() == 'c':
        C = x
        K = C + 273
        F = (9 / 5) * C + 3
        print("Temperature in Celcius:", C, " C")
        print("Temperature in Kelvin:", K, " K")
        print("Temperature in Fahrenheit", F, " F")
    elif s[-1].lower() == 'f':
        C = (x - 32) * 5 / 9
        K = C + 273
        F = x
        print("Temperature in Celcius:", C, " C")
        print("Temperature in Kelvin:", K, " K")
        print("Temperature in Fahrenheit", F, " F")
    else:
        print('Invalid input')
except ValueError:
    print('Invalid input')

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