In many real-world applications, converting temperatures between different units is a common task. For example, meteorologists, scientists, and engineers often need to convert temperatures from Celsius to Fahrenheit or Kelvin. In this challenge, you'll implement a function that converts temperatures between these units using logical operators and conditional statements.
Your task is to write a function convert_temperature
that takes three parameters: a float representing the temperature value, a string representing the unit of the input temperature, and another string representing the desired unit for the output temperature. The function should return a Result
type with either the converted temperature as a float or an error message if the input is invalid.
"Invalid unit"
.Ok
variant of the Result
.The Celsius and Fahrenheit scales are named after the scientists Anders Celsius and Daniel Gabriel Fahrenheit, respectively. The Kelvin scale, on the other hand, is named after Lord Kelvin, a British physicist. Unlike the Celsius and Fahrenheit scales, which are based on the freezing and boiling points of water, the Kelvin scale is an absolute temperature scale based on the concept of absolute zero, the lowest possible temperature where all molecular motion ceases.
F = C * (9/5) + 32
C = (F - 32) * (5/9)
K = C + 273.15
C = K - 273.15