用Python类与对象编程

img

img

img


这个对person类的构造怎么去编程,没有一点思路QAQ,还请各位看看,谢谢各位啦

img

我给你写了一版,供你参考。如果有帮助,望采纳


import math


class Person(object):
    count = 0

    def __init__(self, name):
        self.name = name
        self.__ability = 10
        self.__weight = 5
        self.__height = 50
        Person.count += 1

    def Sport(self, t):
        self.__height += -t ** 2 + t * 6

    def Study(self, t):
        self.__ability += math.log2(t + 1)

    def Eat(self, t):
        self.__weight += 10 * math.sqrt(t)

    def __str__(self):
        return self.name

    def Height(self):
        return self.__height

    def Weight(self):
        return self.__weight

    def Ability(self):
        return self.__ability