Python program to find area of cone circle using inheritance

 

Python program to find the area of cone circle using inheritance

Write a python program with Abstract Class Shape. Cone and Circle are the two classes that derive properties from shape. Also, find the area of the circle and Cone using Inheritance in Python.

Video Tutorial

Source Code to find the area of cone circle using inheritance in python

class shape():
    def area(self):
        raise NotImplementedError()

    def display(self):
        raise NotImplementedError()
        
class circle(shape):
    def __init__(self, r):
        self.r = r
        self.a = 0
    
    def area(self):
        self.a = 3.142 * self.r * self.r
        
    def display(self):
        print ("Area of Circle: ",self.a)
        
class cone(shape):
    def __init__(self, r, h):
        self.r = r
        self.h = h
        self.a = 0
    
    def area(self):
        self.a = 3.142 * self.r * self.r * self.h
        
    def display(self):
        print ("Area of Cone: ",self.a)
        

r = int (input("Enter the Radius of circle and cone:"))
h = int (input("Enter the height cone:"))
cir = circle(3) 
cir.area()
cir.display()

con = cone(3, 4) 
con.area()
con.display()

Output:

Case 1:

Enter the Radius of circle and cone: 3

Enter the height cone: 4

Area of Circle: 28.278

Area of Cone: 113.112

Summary:

This tutorial discusses how to write a Python program to find the area of cone circle using inheritance. If you like the tutorial share it with your friends. Like the Facebook page for regular updates and YouTube channel for video tutorials.

Leave a Comment

Your email address will not be published. Required fields are marked *

Welcome to VTUPulse.com


Computer Graphics and Image Processing Mini Projects -> Click Here

Download Final Year Project -> Click Here

This will close in 12 seconds