Exercise: Temperature Conversion
Leer en Español | Solve Online
Background/Motivation
Converting temperatures between different scales is a fundamental task in science and engineering. The Celsius scale, commonly used in most of the world, and the Fahrenheit scale, used primarily in the United States, are related by a linear equation. Implementing this conversion is a classic exercise to practice arithmetic precedence and floating-point operations.
The Task
Implement a function celsius_to_fahrenheit(celsius: float) -> float that converts a temperature from Celsius to Fahrenheit using the formula:
$$F = (C \times \frac{9}{5}) + 32$$
Specifications
- Function Name:
celsius_to_fahrenheit - Arguments:
celsius(float) - Return Type:
float - Expected Output: The temperature converted to Fahrenheit.
Constraints
- $-273.15 \le \text{celsius} \le 10^6$ (Absolute zero to a very high value)
Example
>>> celsius_to_fahrenheit(0)
32.0
>>> celsius_to_fahrenheit(100)
212.0
>>> celsius_to_fahrenheit(-40)
-40.0
Instructions
- Open
exercises/celsius_to_fahrenheit/solution.py. - Implement the
celsius_to_fahrenheitfunction. - Change
SUBMIT = FalsetoSUBMIT = Trueat the top of the file when you are ready to be graded. - Run
python solution.pylocally to verify your solution with the built-in self-tests.