In: Computer Science
Create a class called triangle_area. The initializing inputs are numbers b and h. In addition to the initialization method, the class must have the area method, which calculates the area of a triangle (A = b x h / 2) and creates an attribute called Area with that value.
#when you paste this code in python editor please follow indentation
#class for calculating area of triangle
class triangle_area():
#constructor for initialization of values
def __init__(self,b,h):
self.b = b
self.h = h
#method for calculaing the area
def area(self):
Area=(b*h)/2
return Area
#main program
#reading input values from user
b = int(input("Enter the Base value : "))
h = int(input("Enter the HEight : "))
#creating object for class
obj = triangle_area(b,h)
#printing result
print("Triangle Area : " ,obj.area())