I learn OOP, I wrote a simple program, but when I invoke the name or age attributes, I get a TypeError. Here is the code itself

from random import randrange female_names = ['Zoy','Penny','Kate'] male_names = ['Joe','Gabe','Mike'] class human: def __init__(self,name,age): self.name = name self.age = age class male(human): def hello(self): print('Hello') class female(human): def hello(self): print('hello') m = male(male_names[randrange(0,3)],randrange(10,40)) m.hello() print(m.name()) print(m.age()) 

I would be very grateful for the help)

    1 answer 1

    This is not a function. To get an attribute, no parentheses are needed.

     print(m.name) print(m.age) 

    Alternatively, you can implement methods in the human class to get the necessary attributes:

     from random import randrange female_names = ['Zoy','Penny','Kate'] male_names = ['Joe','Gabe','Mike'] class human: def __init__(self,name,age): self.name = name self.age = age def get_name(self): return self.name def get_age(self): return self.age class male(human): def hello(self): print('Hello') class female(human): def hello(self): print('hello') m = male(male_names[randrange(0,3)],randrange(10,40)) m.hello() print(m.get_name()) print(m.get_age())