Phython - Temperature conversion code

How to write a Phython Temperature conversion code in Phython ?


T = float(input("Please enter the temperature: "))
      
unitFrom = input("Please enter the scale to convert from (Celsius, Kelvin, Fahrenheit): ")

unitTo = input("Please enter the scale to convert to (Celsius, Fahrenheit and Kelvin): ")


#T is the temperature converted, unitFrom is what scale it is entered in, unitTo is the scale converted to
def convertTemperature(T, unitFrom, unitTo):
    #From Fahrenheit to Celsius and Kelvin
    if unitFrom == "Fahrenheit":
        if unitTo == "Celsius":
            T = (T - 32)/1.8
        elif unitTo == "Kelvin":
            T = (T + 459.67)/1.8
           
    #From Celsius to Fahrenheit and Kelvin
    elif unitFrom == "Celsius":
        if unitTo == "Fahrenheit":
            T = 1.8*T + 32
        elif unitTo == "Kelvin":
            T = T + 273.15
           
    #From Kelvin to Celsius and Fahrenheit
    elif unitFrom == "Kelvin":
        if unitTo == "Celsius":
            T = T - 273.15
        elif unitTo == "Fahrenheit":
            T = 1.8*T - 459.67
       
    return T

#End


Learn More :