Python - Encapsulation and Data Protection
Consider a class that stores a temperature in Celsius internally but exposes it as Fahrenheit using property decorators. Which code correctly implements this?
class Temperature:
def __init__(self, celsius):
self._celsius = celsius
@property
def fahrenheit(self):
# Convert Celsius to Fahrenheit
return (self._celsius * 9/5) + 32
@fahrenheit.setter
def fahrenheit(self, value):
# Convert Fahrenheit to Celsius
self._celsius = (value - 32) * 5/9
# Usage
temp = Temperature(0)
temp.fahrenheit = 212
print(round(temp._celsius))What is the output?
