SIMPLE PYTHON CLASS EXAMPLE TO CALUCLATE THE AREA OF TRIANGLE

in #coding6 years ago
class Triangle:
    pass

triangle1=Triangle()

triangle1.height=10
triangle1.base=12

print(1/2*triangle1.height*triangle1.base)

The output was as follows when I run this program:

Screenshot_2.png

I declare a class named Triangle. Then I created an instance of that class which is triangle1. triangle1 is also the object of the class Triangle. Then I set the attribute of that object triangl1 which as height and base and then finally printing the value by using the formula of area of triangle.

You can run this program online here, just copy paste the code.