+ 1

Syntax Error

So spent about an hour trying to fix this and came up stumped. Just a beginner btw so I might of missed something. It shows syntax error at line 35 where self.employees = employees, look at my profile if you need the code. class Employee(): raise_amount = 1.10 def __init__(self,first,last,pay): self.first = first self.last = last self.pay = pay def fullname(self): print(self.first + '' + self.last) @classmethod def set_raise_amount(cls,amount): cls.raise_amount = amount @classmethod def from_str(cls,emp_str): first, last, pay, sector = emp_str.split('-') return Employee(first, last, pay, sector) class Dev(Employee): def __init__(self,first,last,pay,pro_lang): super().__init__(first,last,pay) self.pro_lang = pro_lang class Manager(Employee): def __init__(self,first,last,pay,employees=None): super().__init__(first,last,pay) if employees is None: return [] else: return self.employees = employees def show_emp(self): for emp in self.employees: print('--->' + emp.fullname()) Dev_1 = Dev('Bill','Gates',37000,'Python') Manager_1 = Manager('Dave','Schumen',50000,[Dev_1]) print(Manager_1.show_emp)

23rd Jun 2020, 6:56 PM
Prog
Prog - avatar
4 Antworten
+ 1
And if they have no employees, you want Manager.employees to equal []? If thats the case, try: ...... def __init__(self, first, last, pay, employees=None): super().__init__(first, last, pay) if self.employees == None: self.employees = [] else: self.employees = employees You may even just want to initialize the Manager.employees value AS an empty list. Skip a step there
23rd Jun 2020, 8:10 PM
Slick
Slick - avatar
+ 1
What are you trying to do at that line? Were you looking to return a bool?
23rd Jun 2020, 7:19 PM
Slick
Slick - avatar
+ 1
Oh right just realized the problem that I thought reurn would set the employees to whatever iI returned. Basic mistakes there :/. Thanks for the help, got the code working and updated it. After the 'if' I just put employees because it woudnt work if I used self.employees.
23rd Jun 2020, 8:41 PM
Prog
Prog - avatar
0
Letting the input that you enter for employees to become the variable 'self.employees'
23rd Jun 2020, 8:05 PM
Prog
Prog - avatar