0% found this document useful (0 votes)
18 views

2. Classes and Object 2- Task 1

The document defines two classes, 'son' and 'daughter', which calculate and display the share of assets for each based on a given percentage. It also includes classes for 'rectangle' and 'square' that provide methods to display their type and calculate their area. Additionally, there are error checks for installment payments and book availability in a library.

Uploaded by

arif895178
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
18 views

2. Classes and Object 2- Task 1

The document defines two classes, 'son' and 'daughter', which calculate and display the share of assets for each based on a given percentage. It also includes classes for 'rectangle' and 'square' that provide methods to display their type and calculate their area. Additionally, there are error checks for installment payments and book availability in a library.

Uploaded by

arif895178
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 1

class son(parent):

def __init__(self,total,Percentage_for_son):
self.Percentage_for_son=Percentage_for_son
parent.total_asset=total
def son_display(self):
self.sp=self.Percentage_for_son*parent.total_asset/100
print("Share of Son is "+str(self.sp)+" Million.")
class daughter(parent):
def __init__(self,total,Percentage_for_daughter):
parent.total_asset=total
self.Percentage_for_daughter=Percentage_for_daughter
def daughter_display(self):
self.dp=self.Percentage_for_daughter*parent.total_asset/100
print("Share of Daughter is "+str(self.dp)+" Million.")

####################### TASK 2# ##########################


class rectangle():
def display(self):
print("This is a Rectangle")
def area(self,l,b):
self.l=l
self.b=b
self.area=self.l*self.b
print("Area of Rectangle is {}".format(self.area))
class square():
def display(self):
print("This is a Square")
def area(self,s):
self.s=s
self.area=self.s*self.s
print("Area of square is {}".format(self.area))

if(installment>3):
raise ValueError("Maximum Permitted Number of Installments is 3")
elif(installment==0):
raise ZeroDivisionError("Number of Installments cannot be Zero.")
else:
amount=memberfee/installment
print("Amount per Installment is {}".format(amount))
li=["Philosophers stone","Chamber of Secrets","prisoner of azkaban","Goblet
of Fire","order of phoenix","Half Blood Prince","deathly hallows 1","deathly
hallows 2"]
c=li.count(book)
if(c==0):
print("No such book exists in this section")
else:
print("It is available in this section")

if(c==0):
raise NameError("No such book exists in this section")
else:
print("It is available in this section")

You might also like