class TemperatureConverter: def __init__(self, temp: float) -> None: self.temp = temp self._celsius_to_fahrenheit_factor = 9/5 self._celsius_to_fahrenheit_offset = 32 def fahrenheit_to_celsius(self) -> float: celsius = (self.temp - 32) * (5/9) return round(celsius, 2) def celsius_to_fahrenheit(self) -> float: fahrenheit = (self.temp * self._celsius_to_fahrenheit_factor) + self._celsius_to_fahrenheit_offset return round(fahrenheit, 2)
- class TemperatureConverter:
def __init__(self, temp):- def __init__(self, temp: float) -> None:
- self.temp = temp
self._k1 = 5 / 9self._k2 = self._k1 * 32- self._celsius_to_fahrenheit_factor = 9/5
- self._celsius_to_fahrenheit_offset = 32
def fahrenheit_to_celsius(self):return round(self.temp * self._k1 - self._k2, 2)- def fahrenheit_to_celsius(self) -> float:
- celsius = (self.temp - 32) * (5/9)
- return round(celsius, 2)
def celsius_to_fahrenheit(self):return round((self.temp + self._k2) / self._k1, 2)- def celsius_to_fahrenheit(self) -> float:
- fahrenheit = (self.temp * self._celsius_to_fahrenheit_factor) + self._celsius_to_fahrenheit_offset
- return round(fahrenheit, 2)