问题

    题目标题: 美国数学家维纳(N.Wiener)智力早熟,11岁就上了大学。他曾在1935~1936年应邀来中国清华大学讲学。一次,他参加某个重要会议,年轻的脸孔引人注目。于是有人询问他的年龄,他回答说:“我年龄的立方是个4位数。我年龄的4次方是个6位数。这10个数字正好包含了从0到9这10个数字,每个都恰好出现1次。”请你推算一下,他当时到底有多年轻。

    代码实现

    • 封装错误```python class LenError(Exception): def init(self, Array_len, Get_Number):

      1. self._Array_len = Array_len
      2. self._Get_Number = Get_Number

      def str(self):

        return f"The maximum length of the object is {self._Array_len}, " \
               f"and the {self._Get_Number} you enter exceeds the maximum limit"
      

    class IntError(Exception): def init(self, _Get_Number): self._Get_Number = _Get_Number

    def __str__(self):
        return f"The value entered must be greater than or equal to 0, " \
               f"but the value participating in the operation is {self._Get_Number}"
    

    class NotInError(Exception): def init(self, _Get_Char, Get_Str): self._Get_Char = _Get_Char self._Get_Str = Get_Str

    def __str__(self):
        return f"The '{self._Get_Char}' character you are looking " \
               f"for has not appeared in this string '{self._Get_Str}'"
    

    class IntRangeError(Exception): def __str(self): return “Values range from 0 to 100, check the value of the parameter, the value exceeds the range”

    class Errors: def init(self, Number): self.Number = Number

    @property
    def Int_Range_Error(self):
        if self.__Int_Range_Error__():
            return None
        else:
            raise Int_Range_Error()
    
    def __Int_Range_Error__(self):
        if 0 <= self.__Number__ <= 100:
            return True
        else:
            return False
    
    
    - **统计字符出现次数**```python
    class character:
        def __init__(self):
            self._Get_Str = None
            self._top_Count = 0
            self._InChar = None
    
        @property
        def Get_Str(self):
            return self._Get_Str
    
        @Get_Str.setter
        def Get_Str(self, Get_Str):
            self._Get_Str = Get_Str
    
        @property
        def top_Count(self):
            return self._top_Count
    
        @top_Count.setter
        def top_Count(self, top_Count):
            self._top_Count = top_Count
    
        @property
        def Clear_Space(self):
            self._Get_Str = self._Get_Str.replace(" ", "")
            return self._Get_Str
    
        @property
        def InChar(self):
            return self._InChar
    
        @InChar.setter
        def InChar(self, InChar):
            self._InChar = InChar
    
        @property
        def Get_word_count(self):
            return self._Get_word_count()
    
        @property
        def Get_top_count(self):
            self._IntError()
            return self._Get_top_count(top_Count=self.top_Count)
    
        @property
        def IsInStr(self):
            _return = False
            if self._InChar in self._Get_Str:
                _return = True
            else:
                raise NotInError(self._InChar, self._Get_Str)
            return _return
    
        @property
        def Number_of_appearances(self):
            if self.IsInStr is True:
                return self._Number_of_appearances()
            else:
                raise NotInError(self._InChar, self._Get_Str)
    
        def _IntError(self):
            if self.top_Count <= 0:
                raise IntError(self.top_Count)
    
        def __str_to_list(self):
            return list(str(self._Get_Str))
    
        def _Get_word_count(self):
            return Counter(self.__str_to_list())
    
        def _Get_top_count(self, top_Count):
            if self._len_word_count() >= self.top_Count:
                return self._Get_word_count().most_common(top_Count)
            else:
                raise LenError(self._len_word_count(), self.top_Count)
    
        def _len_word_count(self):
            return self._Get_word_count().__len__()
    
        def _Number_of_appearances(self):
            return dict(self.Get_word_count)[self.InChar]
    
    • 功能代码```python class Guesstheage: def __init(self):

        self.__i__ = 0
        self.__i__3__ = 0
        self.__i__4__ = 0
        self.__int_str__ = ""
        self._Guess_the_age_ = 0
        self.__str_len__ = 0
      

      @property def Guess_the_age(self):

        for i in range(1, 30):
            self.__i__ = i
            if self.__Guess_the_age__():
                return self.__i__
      

      def Guess_the_age(self):

        if self.__Int_for_str__():
            try:
                if self.__appears_once__():
                    return self.__i__
            except NotInError:
                pass
      

      def appears_once(self):

        new_character = character()
        new_character.Get_Str = self.__int_str__
        for i in range(0, 10):
            new_character.InChar = str(i)
            if new_character.Number_of_appearances != 1:
                return False
        return True
      

      def _i_n_len(self):

        self.__i__3__ = self.__i__ ** 3
        self.__i__4__ = self.__i__ ** 4
        self.__int_str__ = self.__i__3__.__str__() + self.__i__4__.__str__()
        self.__str_len__ = len(self.__int_str__)
      

      def Int_for_str(self):

        self.__i_n_len_()
        if len(str(self.__i__3__)) == 4 and len(str(self.__i__4__)) == 6:
            return True
        else:
            return False
      

      ```

    • 测试代码 mainpython if __name__ == '__main__': print(Guess_the_age().Guess_the_age) # 18