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 ?
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')
Comments
Leave a comment