-1

I am trying to make this code work, but I am missing something.

class animal():
    def __init__(self, weight):
        self.weigth = weight

    @classmethod
    def print(self, weight):
        self.printWeight(weight)


class human(animal):
    @classmethod
    def printWeight(self, weight):
        print(self.weigth)

human.print(1)

which gives AttributeError: type object 'human' has no attribute 'weigth'

any suggestions ?

Thanks !

GMV871
  • 43
  • 1
  • 6
  • Why did you mark those methods as `@classmethod`? Do you know what it does? – matszwecja Sep 01 '23 at 09:12
  • What do you think `classmethod` does? Why are you using that? Your class doesn't have that attribute, it is an instance attribute not a class attribute – juanpa.arrivillaga Sep 01 '23 at 09:13
  • Also, are you wanting to print the argument, or the attribute? Doesn’t make much sense to have weight as an attribute, and also pass it to every method as an argument. – deceze Sep 01 '23 at 09:24
  • All in all, there's a bunch of problems with the code and I suggest finding a basic tutorial for classes in Python and following that to get a correct understanding of what is what. – matszwecja Sep 01 '23 at 09:26
  • See [this question](https://stackoverflow.com/q/12179271) to know what `@classmethod` means and how to use it correctly. Additionally, watch [this video by mCoding](https://www.youtube.com/watch?v=SXApHXsDe8I). – InSync Sep 01 '23 at 09:26

0 Answers0