209k views
2 votes
Suppose class Person is the parent of class Employee. Complete the following code:

class Person :
def __init__(self, first, last) :
self.firstname = first
self.lastname = last
def Name(self) :
return self.firstname + " " + self.lastname
class Employee(Person) :
def __init__(self, first, last, staffnum) :
Person.__init__(self,first, last) self.staffnumber = staffnum
def GetEmployee(self) :
return self.Name() + ", " + self.staffnumber
x = Person("Sammy", "Student")
y = Employee("Penny", "Peters", "805")
print(x.Name())
print(y.GetEmployee())

User Veelkoov
by
3.6k points

1 Answer

1 vote

Answer:

Step-by-step explanation:

There is nothing wrong with the code it is complete. The Employee class is correctly extending to the Person class. Therefore, the Employee class is a subclass of Person and Person is the parent class of Employee. The only thing wrong with this code is the faulty structure such as the missing whitespace and indexing which is crucial in Python. This would be the correct format. You can see the output in the picture attached below.

class Person :

def __init__(self, first, last) :

self.firstname = first

self.lastname = last

def Name(self) :

return self.firstname + " " + self.lastname

class Employee(Person) :

def __init__(self, first, last, staffnum) :

Person.__init__(self,first, last)

self.staffnumber = staffnum

def GetEmployee(self) :

return self.Name() + ", " + self.staffnumber

x = Person("Sammy", "Student")

y = Employee("Penny", "Peters", "805")

print(x.Name())

print(y.GetEmployee())

Suppose class Person is the parent of class Employee. Complete the following code-example-1
User Dekts
by
3.3k points