Program - function to convert temperature as per user mention.


Topic: Program - function to convert temperature as per user mention.

Solution

def temp_converter(temp , temp_given_in= 'F'):
    if temp < 0:
        raise ValueError("Input Temperature is Negative")
    else:
        if temp_given_in.upper() == 'F':
            t = (temp-32)*5/9
            return t
        elif temp_given_in.upper() == 'C':
            t = 9/5 * (temp) + 32
            return t
        elif temp_given_in.upper() not in ('C' , 'F'):
            raise NotImplementedError("Invalid Temperature Coneversion")



List all Python Programs