In: Computer Science
2. Write python code for the below instructions (don’t forget to use the keyword “self” where appropriate in your code):
A. Define a Parent Class called Person
a. Inside your Person class, define new member variables called name, age, and gender. Initialize these variables accordingly.
b. Define the constructor to take the following inputs: name, age, and gender. Assign these inputs to member variables of the same name.
B. Define Child Class called Employee that inherits from the Person Class
a. Inside your Child class, define new member variables called title and salary. Initialize these variables accordingly.
b. Define the constructor to take the following inputs: name, age, gender, title, and salary. Assign these inputs to Class member variables of the same name. Note, you will need to specifically call the Parent constructor method inside the Child constructor, passing the appropriate inputs to the Parent constructor.
C. Instantiate an Employee object called George with the following inputs: name = “George”, age = 30, gender = “Male”, title = “Manager”, and salary = 50000.
D. Print out the object’s name, age, gender, title, and salary in one print statement to the console window. Your output should look like:
“George's info is: Name is George, Age is 30, Gender is Male, Title is Manager, and Salary is 50000”
class Person:
def __init__(self, name, age, gender):
self.name = name
self.age = age
self.gender = gender
class Employee(Person):
def __init__(self, name, age, gender, title, salary):
Person.__init__(self, name, age, gender)
self.title = title
self.salary = salary
George = Employee("George", 30, "Male", "Manager", 50000)
print("%s's info is: Name is %s, Age is %d, Gender is %s, Title is %s, and Salary is %d" %(George.name, George.name, George.age, George.gender, George.title, George.salary))