25 XP

4. Celsius to Fahrenheit

Beginner math

Write a function to_fahrenheit(celsius) that takes a temperature in degrees Celsius and returns the same temperature in degrees Fahrenheit.

The formula is: multiply by 9, divide by 5, then add 32. Dividing with / always gives a decimal number (a float), so the answer is a float such as 212.0, even when the temperature is a whole number.

Example 1

Inputcelsius = 100
Output212.0
Explanation100 * 9 / 5 + 32 = 180.0 + 32 = 212.0.

Example 2

Inputcelsius = 0
Output32.0
Explanation0 * 9 / 5 + 32 = 0.0 + 32 = 32.0.

Example 3

Inputcelsius = -40
Output-40.0
Explanation-40 degrees is the same on both scales.

Constraints

  • celsius is a whole number or a decimal from -273.15 to 1000. It can be negative.
  • Decimal arithmetic can be a tiny bit off: -273.15 gives -459.66999999999996, not -459.67. That's fine: an answer within 0.000000001 of the expected one counts as right.

Submit also runs 4 more tests you can't see.

Practises Numbers and Math (lesson 3).

Code
def to_fahrenheit(celsius):
    """Convert a temperature from Celsius to Fahrenheit.

    celsius: int or float, the temperature in degrees C
    Returns: float, the same temperature in degrees F
    """
    # Write your code here
    pass