Skip to content

Instantly share code, notes, and snippets.

@ehermes
Created February 17, 2016 19:56
Show Gist options
  • Select an option

  • Save ehermes/cb1a410c3b74160a9c32 to your computer and use it in GitHub Desktop.

Select an option

Save ehermes/cb1a410c3b74160a9c32 to your computer and use it in GitHub Desktop.
class Temperature(object):
def __init__(self, T=0, unit='C'):
if unit == 'C':
self.C = T
elif unit == 'F':
self.F = T
elif unit == 'K':
self.K = T
else:
raise ValueError
@property
def C(self):
return self.K - 273.15
@C.setter
def C(self, T):
self.K = T + 273.15
@property
def F(self):
return (self.C * 1.8) + 32
@F.setter
def F(self, T):
self.C = (T - 32) / 1.8
freezing = Temperature(0, 'C')
print(freezing.C)
print(freezing.F)
print(freezing.K)
boiling = copy.copy(freezing)
boiling.C = 100
print(boiling.C)
print(boiling.F)
print(boiling.K)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment