Answer to Question #298076 in Python for satyasrini

Question #298076

Temperature Conversion

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.

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

first output should contain the Celsius value and the unit of the Celsius without any space.

second l output should contain the Fahrenheit value and the unit of the Fahrenheit without any space.

third output should contain the Kelvin value and the unit of the Kelvin without any space.

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.

imp: here ouput gives 289.1k instead of 289.0k why ?



1
Expert's answer
2022-02-15T11:24:24-0500
print('What temperature would you like to enter?')
print('1. Fahrenheit (enter F)\n2. Celsius (enter C)\n3. Kelvin (enter K)')

temp = input().lower()

if temp == 'f' or temp == 'c' or temp == 'k':
    print('Enter number of degrees')
    if temp == 'f':
        fahrenheit = float(input())
        celsius = round((fahrenheit - 32) * 5 / 9, 2)
        kelvin = celsius + 273
    elif temp == 'c':
        celsius = float(input())
        fahrenheit = round((9 * celsius) / 5 - 32, 2)
        kelvin = celsius + 273
    elif temp == 'k':
        kelvin = float(input())
        celsius = kelvin - 273
        fahrenheit = round((9 * celsius) / 5 - 32, 2)
    
    print("Celsius temperature ", celsius)
    print('Fahrenheit temperature', fahrenheit)
    print('Kelvin temperature', kelvin)

else:
    print('Unknown temperature')

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