def main() :
a = Employee("Boss",11000)
b = Employee("Jacob",3000)
c = Employee("Michael",5000)
print(a)
print(b)
print(c)
class Employee:
def __init__(self, name, salary):
self.__name = name
self.__salary = salary
def name(self):
self.__name = name
def salary(self):
self.__salary = salary
def count(self, count=0):
self.__count=count
self.__count += 1
def __str__(self):
return "No : %d name : %s salary : %d" %(self.__count, self.__name, self.__salary)
main()
I want it to be printed like this and I don't want to change my main function.
No : 1 name : Boss salary : 11000
No : 2 name : Jacob salary : 3000
No : 3 name : Michael salary : 5000
Is there a problem while counting from self.__count or is there something to add?
The error what I got is 'AttributeError: 'Employee' object has no attribute '_Employee__count''
And when I try to change my code like this:
def main() :
a = Employee("Boss",11000)
b = Employee("Jacob",3000)
c = Employee("Michael",5000)
print(a)
print(b)
print(c)
class Employee:
def __init__(self, name, salary):
self.__name = name
self.__salary = salary
**self.__count =0**
def name(self):
self.__name = name
def salary(self):
self.__salary = salary
**def count(self, count=0):
self.__count += 1**
def __str__(self):
return "No : %d name : %s salary : %d" %(self.__count, self.__name, self.__salary)
main()
The result was like this:
''' No : 0 name : Boss salary : 11000 No : 0 name : Jacob salary : 3000 No : 0 name : Michael salary : 5000 '''
At the end, 'self'.__count = 0' I think program took this part and printed it out, where is the problem?