Python Programming For Beginners part 4
Task 1: Write a program using object oriented method to print "Hello I am a constructor on the
screen".
print(" -----Hello word-----")
class hello():
def dsp(self):
print("Hello I am a constructor on the screen")
if __name__=="__main__":
hp=hello()
hp.dsp()
Task 2: Write a program using object oriented method to calculate the area. It should require
two attributes width W and Height H.
class Area:
pass
R=Area()
R.width = 5
R.height = 7
print("Hieght is : ",R.width)
print(" Width is : ",R.height)
print("Total Area Is :",R.width*R.height)
Task 3: Write a program using OOP method to calculate the area. It should require two values of
attributes W and H (the user will enter the values of w and h in run time).
class Area:
def __init__(self):
self.w = float(input("Enter the value of w :"))
self.h = float(input("Enter the value of h :"))
print("Total Area Is",self.w*self.h)
R=Area()


No comments:
Post a Comment