#!/bin/python3
task 1 Inheritance: parent and children share
import math
import os
import random
import re
import sys
class parent:
def __init__(self,total_asset):
self.total_asset = total_asset
def display(self):
print("Total Asset Worth is "+str(self.total_asset)+" Million.")
print("Share of Parents is "+str(round(self.total_asset/2,2))+" Million.")
class son(parent):
def __init__(self, total_asset,Percentage_for_son):
self.Percentage_for_son=Percentage_for_son
parent.__init__(self,total_asset)
def son_display(self):
s = round((self.total_asset * self.Percentage_for_son)/100 ,2)
print("Share of Son is "+str(s)+" Million.")
class daughter(parent):
def __init__(self, total_asset,Percentage_for_daughter):
self.Percentage_for_daughter=Percentage_for_daughter
parent.__init__(self,total_asset)
def daughter_display(self):
d=round((self.total_asset*self.Percentage_for_daughter)/100,2)
print("Share of Daughter is "+str(d)+" Million.")
# It is expected to create two child classes 'son' & 'daughter' for the above class 'parent'
#
#Write your code here
if __name__ == '__main__':
t = int(input())
sp = int(input())
dp = int(input())
obj1 = parent(t)
obj2 = son(t,sp)
obj2.son_display()
obj2.display()
obj3 = daughter(t,dp)
obj3.daughter_display()
obj3.display()
print(isinstance(obj2,parent))
print(isinstance(obj3,parent))
print(isinstance(obj3,son))
print(isinstance(obj2,daughter))
task 2 : polymosphism
#!/bin/python3
import math
import os
import random
import re
import sys
class rectangle:
def display(self):
print("This is a Rectangle")
def area(self,Length,Breadth):
self.Length=Length
self.Breadth=Breadth
arear=self.Length*self.Breadth
print("Area of Rectangle is "+str(arear))
class square:
def display(self):
print("This is a Square")
def area(self,Side):
self.Side=Side
areas=self.Side**2
print("Area of square is "+str(areas))
# Write your code here
if __name__ == '__main__':
l = int(input())
b = int(input())
s = int(input())
obj1 = rectangle()
obj1.display()
obj1.area(l,b)
obj2 = square()
obj2.display()
obj2.area(s)
Comments
Post a Comment