Program - function to return speed converer as per user mention data


Topic: Program - function to return speed converer as per user mention data

Solution

def speed_converter(speed , dist = 'KM', time = 'HR'):
    if speed < 0 or type(dist) == str or type(time) == str:
        raise ValueError("Invalid Input Format")
    else:
        if dist.upper == 'KM':
            if time.upper()  == 'S':
                return True
            elif time.upper == 'MS':
                return True
            elif time.upper() == 'M':
                return True
            elif time.upper() == 'HR':
                return True
            elif time.upper() == 'DAY':
                return True
            else:
                raise ValueError("Valid Distance Invalid Time")
        elif dist.upper == 'M':
            if time.upper()  == 'S':
                return True
            elif time.upper == 'MS':
                return True
            elif time.upper() == 'M':
                return True
            elif time.upper() == 'HR':
                return True
            elif time.upper() == 'DAY':
                return True
            else:
                raise ValueError("Valid Distance Invalid Time")
        elif dist.upper == 'FT':
            if time.upper()  == 'S':
                return True
            elif time.upper == 'MS':
                return True
            elif time.upper() == 'M':
                return True
            elif time.upper() == 'HR':
                return True
            elif time.upper() == 'DAY':
                return True
            else:
                raise ValueError("Valid Distance Invalid Time")
        elif dist.upper == 'YRD':
            if time.upper()  == 'S':
                return True
            elif time.upper == 'MS':
                return True
            elif time.upper() == 'M':
                return True
            elif time.upper() == 'HR':
                return True
            elif time.upper() == 'DAY':
                return True
            else:
                raise ValueError("Valid Distance Invalid Time")
        else:
            raise ValueError("Invalid User Distance Input")



List all Python Programs