INNER CODE UNIT · Python

convert_to_celsius

fzumstein/python-for-excel · pep8_sample.py:16

def convert_to_celsius(degrees, source="fahrenheit"):
    """This function converts degrees Fahrenheit or Kelvin
    into degrees Celsius.
    """
    if source.lower() == "fahrenheit":
        return (degrees - 32) * (5 / 9)
    elif source.lower() == "kelvin":
        return degrees - 273.15
    else:
        # Exceptions will be introduced in Chapter 10
        raise ValueError(f"Don't know how to convert from {source}")


celsius = convert_to_celsius(44, source="fahrenheit")
non_celsius_scales = TEMPERATURE_SCALES[:-1]

print("Current time: " + dt.datetime.now().isoformat())
print(f"The temperature in Celsius is: {celsius}")

View source record →

📰 Research Paper
Loading…
⏳ Fetching content…