METALARISING 发表于 2023-9-1 16:52:50

半自动摄氏度转华氏度



class Celsius:
    def __init__(self, value = 0):
      self.value = float(value)

    def __get__(self, instance, owner):
      return self.value

    def __set__(self, instance, value):
      self.value = float(value)

class Fahrenheit:
    def __get__(self, instance, owner):
      return instance.cel * 1.8 + 32

    def __set__(self, instance, value):
      instance.cel = (float(value) - 32) / 1.8

class Temperatuure:
    cel = Celsius()
    fah = Fahrenheit()

running以后写:
temp = Tempertuure()
                              ^
                              写数字(默认为零)

rtiuyttr 发表于 2023-9-7 23:45:43

页: [1]
查看完整版本: 半自动摄氏度转华氏度