INNER CODE UNIT · Python
TemperatureConverter
fzumstein/python-for-excel · pep8_sample.py:12
class TemperatureConverter:
pass # Doesn't do anything at the moment
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")