1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
Llana [10]
3 years ago
14

Create a Person Class that:

Computers and Technology
1 answer:
alekssr [168]3 years ago
6 0

Answer:

See explaination

Explanation:

#Create a person class

class Person:

#Constructor

def __init__(self,firstName,lastName,age,gender):

if firstName=="":

raise Exception('First name should not be empty')

self.firstName=firstName

if lastName=="":

raise Exception('Last name should not be empty')

self.lastName=lastName

if(age<0 or age>100):

raise Exception('Age should be within range 0-100')

self.age=age

if(gender!='M' and gender!='F' and gender!='T'):

raise Exception('Gender should be M/F/T')

self.gender=gender

#Create a student class as a subclass of Person

class Student(Person):

#constructor

def __init__(self,firstName,lastName,age,gender,gpa):

Person.__init__(self,firstName,lastName,age,gender)

if(gpa<0 or gpa>4):

raise Exception('GPA should be 0-4')

self.gpa=gpa

#Function to display graduation status

def gradStatus(self):

print('Getting There!!')

#Create a graduate class as a subclass of Student

class Graduate(Student):

#constructor

def __init__(self,firstName,lastName,age,gender,gpa,gradYear,jobStatus):

Student.__init__(self,firstName,lastName,age,gender,gpa)

if(not gradYear.isdigit()):

raise Exception('Graduation year should be integer')

self.gradYear=gradYear

if(jobStatus!='Y' and jobStatus!='N'):

raise Exception('Job status should be Y/N')

self.jobStatus=jobStatus

#Function to display graduation status

def gradStatus(self):

print('I am Finished!!')

#Function to calculate total graduate student

def totalGraduates(graduate):

return len(graduate)

#Average gpa

def avgGpa(graduate):

sum=0

for grad in graduate:

sum+=grad.gpa

return sum/len(graduate)

#Average age

def avgAge(graduate):

avg=0

count=0

for grad in graduate:

if grad.gender=='M' or grad.gender=='F':

avg+=grad.age

count+=1

return avg/count

#Total Number of Male and Female Graduated Students who have jobs.

def totalJob(graduate):

count=0

for grad in graduate:

if grad.jobStatus=='Y':

count+=1

return count

#Test method

def main():

#Create 5 graduates

graduate=[]

graduate.append(Graduate("Adorn",'Antony',20,'M',3.0,"2011",'Y'))

graduate.append(Graduate("Amelia",'Anus',20,'F',3.5,'2011','Y'))

graduate.append(Graduate("Bambi",'Antony',20,'F',3,'2011','N'))

graduate.append(Graduate("Stephen",'Josh',20,'M',2,'2011','N'))

graduate.append(Graduate("Milli",'Markos',20,'F',4,'2011','Y'))

#Total Number of Graduated Students (use a dunder method to display this).

print('Total Number of Graduated Students: ',totalGraduates(graduate))

#Average GPA of all Graduated Students

print('Average GPA of all Graduated Students: %.2f'%avgGpa(graduate))

#Average Age of the Male and the Female Graduated Students

print('Average age of the Male and the Female Graduated Students: %.2f'%avgAge(graduate))

#Total Number of Male and Female Graduated Students who have jobs.

print('Total Number of Male and Female Graduated Students who have jobs: ',totalJob(graduate))

main()

You might be interested in
Please help ASAP!!! :))
Talja [164]

Answer:

You can upgrade the OS by applying SECURITY patches to the server

Explanation:

I can't think of anything else it could be

3 0
3 years ago
Which categories format cells
fredd [130]
Currency, percentage, date, time, fraction, scientific
4 0
3 years ago
Read 2 more answers
Search engines are used to find a specific entry in a database.<br><br> True or false?
KatRina [158]
True true true true I think
8 0
3 years ago
Read 2 more answers
After reading passage “the incredible machine” why do you think the article has been titled so?
Vitek1552 [10]
I haven’t read it, but just by the title it was probably talking about an incredible machine that was new to people.
7 0
3 years ago
In a(n) ____ design, the remote user's keystrokes are transmitted to the mainframe, which responds by sending screen output back
Harrizon [31]

Answer:

I think it would be centralized

4 0
3 years ago
Other questions:
  • You are replacing the toner cartridge for an old laser printer. You are concerned that several internal components are reaching
    8·1 answer
  • People with healthy media diets:
    12·1 answer
  • The most important protocol at the internet layer is ____.
    13·1 answer
  • Which is an advantage of setting bookmarks?
    15·1 answer
  • When you are cut off in traffic by another driver and you respond by “flipping him the bird,” you are using a type of gesture ca
    7·1 answer
  • Which of the following is not System Software?
    5·1 answer
  • Which data type is –7?<br><br> int<br><br> single<br><br> string<br><br> float
    15·1 answer
  • What is a megavirus in computing
    8·2 answers
  • Ingredient Adjuster
    11·1 answer
  • What is a thread? what resources does it share with other threads in the same process?
    15·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!