adding all files done so far
This commit is contained in:
32
learning/super/class_1.py
Normal file
32
learning/super/class_1.py
Normal file
@@ -0,0 +1,32 @@
|
||||
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())
|
||||
Reference in New Issue
Block a user