Temperature Converter

Easy
13
81.7% Acceptance

In this lab, you will create a Python function named convert_temperature. This function will convert a given temperature from one unit to another and round the result to two decimal places.

Function Specifications

  • Name: convert_temperature
  • Parameters:
    • value (float): The temperature value to convert.
    • input_unit (string): The unit of the input value ('c' for Celsius, 'f' for Fahrenheit, 'k' for Kelvin).
    • output_unit (string): The unit to convert to ('c', 'f', 'k').

Output

The function should return the converted temperature as a floating-point number, rounded to two decimal places.

Examples

  1. Celsius to Fahrenheit:
    • Input: value = 0, input_unit = 'c', output_unit = 'f'
    • Expected Output: 32.00
  2. Fahrenheit to Kelvin:
    • Input: value = 32, input_unit = 'f', output_unit = 'k'
    • Expected Output: 273.15

Edge Cases

  • If the input_unit and output_unit are the same, return the value rounded to two decimal places.
  • If the input_unit or output_unit is not one of the specified values ('c', 'f', 'k'), the function's behavior is undefined.

Conversion Formulae

formulae for labs