I'm practicing classes by making an employee management program.
I made a class for special needs employees, which has a couple of methods. The method in question is def show_needs()
.
employer_need = Special_emp("louis", 35, 6000, "Programmer", [])
print(employer_need.show_needs())
The output of this code is "None", although i assigned a list to it. and the output after adding some needs:
employer_need.add_need("Autistic")
employer_need.add_need("Partially blind")
print(employer_need.show_needs())
is this
--> Autistic
--> Partially blind
None
It prints the list but prints "None" with it too, and I can't understand why.
class Employee:
Employees = 0
raise_amount = 1.01
def __init__(self, name, age, pay):
self.name = name
self.age = age
self.pay = pay
Employee.Employees += 1
class Special_emp(Employee):
def __init__(self, name, age, pay, occupation, special_needs=None):
super().__init__(name, age, pay)
self.occupation = occupation
if special_needs is None:
self.special_needs = []
else:
self.special_needs = special_needs
def add_need(self, need):
if need not in self.special_needs:
self.special_needs.append(need)
def remove_need(self, need):
if need in self.special_needs:
self.special_needs.remove(need)
def show_needs(self):
for need in self.special_needs:
print("-->", need)