Temperature Converter
Easy
18
81.6% 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
- Celsius to Fahrenheit:
- Input:
value = 0, input_unit = 'c', output_unit = 'f'
- Expected Output:
32.00
- Input:
- Fahrenheit to Kelvin:
- Input:
value = 32, input_unit = 'f', output_unit = 'k'
- Expected Output:
273.15
- Input:
Edge Cases
- If the
input_unit
andoutput_unit
are the same, return thevalue
rounded to two decimal places. - If the
input_unit
oroutput_unit
is not one of the specified values ('c', 'f', 'k'), the function's behavior is undefined.