Question

In: Computer Science

2. Write python code for the below instructions (don’t forget to use the keyword “self” where...

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”

Solutions

Expert Solution

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))


Related Solutions

what are the differences/similarity between the keyword "this" in java and the keyword "self" in python...
what are the differences/similarity between the keyword "this" in java and the keyword "self" in python and why or when should we use these two keywords? if you could provide a code example side by side that would be great! thank you!
Code in python Write a while loop code where it always starts form 2. Then it...
Code in python Write a while loop code where it always starts form 2. Then it randomly chooses a number from 1-4. If the number 4 is hit then it will write “TP” if the number 1 is hit then it will write”SL”. It will rerun the program every time the numbers 1 and 5 are hit. The code should also output every single number that is randomly chosen. 2 of the same numbers can't be chosen back to back...
Code the following in bash and run. Please show full code and don’t forget to comment...
Code the following in bash and run. Please show full code and don’t forget to comment your code. Make a code that takes any list of numbers and calculates and displays the mean, median and mode.
Use python programming to write this code and provide a screen short for the code. 2....
Use python programming to write this code and provide a screen short for the code. 2. Write a function that takes one argument (a string) and returns a string consisting of the single character from that string with the largest value. Your function should contain a for loop. You can assume that the input to your function will always be a valid string consisting of at least one character. You can assume that the string will consist only of lower-case...
Write this code in python Debugging: Use the Debugging Coin Toss code below as the basis...
Write this code in python Debugging: Use the Debugging Coin Toss code below as the basis for this project. Get the program running exactly as it appears in the text. It will run as written. Although it runs, does it run (behave) correctly? That is where you will focus your debugging efforts. Code: import random guess = ' ' while guess not in ('heads', 'tails'):      print('Guess the coin toss! Enter heads or tails: ')      guess = input() toss...
code in python write a code where the initial value is compounded by a multiplier, rounded...
code in python write a code where the initial value is compounded by a multiplier, rounded to the nearest tenth Output: Initial Value: 10 Multiplier: 1.4 Number of compounds: 10 Your Values are: 10 , 14, 19.6 , 27.4, 38.4, 53.8, 75.3, 105.4, 147.6, 206.6
Use Python to solve: show all code: 2) For the last assignment you had to write...
Use Python to solve: show all code: 2) For the last assignment you had to write a program that calculated and displayed the end of year balances in a savings account if $1,000 is put in the account at 6% interest for five years. The program output looked like this: Balance after year 1 is $ 1060.0 Balance after year 2 is $ 1123.6 Balance after year 3 is $ 1191.02 Balance after year 4 is $ 1262.48 Balance after...
Write a simple Java code to make a Binary Tree for the following tree: Don’t use...
Write a simple Java code to make a Binary Tree for the following tree: Don’t use serializable interface implantation /** Class to encapsulate a tree node. */ protected static class Node implements Serializable {
Write a 3 pages paper about euthonesia and don’t forget to cite your sources. Do not...
Write a 3 pages paper about euthonesia and don’t forget to cite your sources. Do not forget the reference page.
List the adult reference range for the following tests:   use your book and don’t forget labtestsonline.org as...
List the adult reference range for the following tests:   use your book and don’t forget labtestsonline.org as a resource Reticulocyte % Serum Iron Serum ferritin             Male             Female TIBC Transferrin saturation % Complete the following chart for the differential diagnosis of Microcytic/Hypochromic Anemias Anemia Fe Level Ferritin TIBC % Saturation Reticulocyte Iron Deficiency Iron deficiency with treatment for 12 days Anemia Beta Thalassemia Minor Hereditary Hemochromatosis Sideroblastic Anemia Explain ferritin levels replace the necessity of performing bone marrow aspirations on cases of...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT