33 lines
842 B
Python
33 lines
842 B
Python
class Celsius:
|
|
def __init__(self, temperature=0):
|
|
print('initalising')
|
|
self.temperature = temperature
|
|
|
|
def __repr__(self):
|
|
return(f'current temperature is {self.temperature} degrees C')
|
|
|
|
def to_fahrenheit(self):
|
|
return (self.temperature * 1.8) + 32
|
|
|
|
def get_temperature(self):
|
|
print("Getting value")
|
|
return self._temperature
|
|
|
|
def set_temperature(self, value):
|
|
if value < -273:
|
|
raise ValueError("Temperature below -273 is not possible")
|
|
print("Setting value")
|
|
self._temperature = value
|
|
return value
|
|
|
|
temperature = property(get_temperature, set_temperature)
|
|
|
|
|
|
# c = Celsius(20)
|
|
# print(Celsius(20).get_temperature)
|
|
|
|
# print(Celsius(20).set_temperature(25))
|
|
# Celsius(20).get_temperature()
|
|
c = Celsius()
|
|
print(c.to_fahrenheit())
|