Sunday, 23 January 2022

Write python script using package to calculate area and volume of cube and sphere

Slip 6 Q 1

CODE:


import math

class cube():
    def __init__(self,edge):
        self.edge=edge
       
    def cube_area(self):
        cubearea=6*self.edge*self.edge
        print("Area of cube :",cubearea)
   
    def cube_volume(self):
        cubevolume=self.edge*self.edge*self.edge
        print("Volume of cube :",cubevolume)

class sphere():
    def __init__(self,radius):
        self.radius=radius
       
    def sphere_area(self):
        spherearea=4*math.pi*self.radius*self.radius
        print("Area of sphere :",spherearea)
       
    def sphere_volume(self):
        spherevolume=float(4/3*math.pi*self.radius**3)
        print("volume of sphere :",spherevolume)
       
e1=cube(5)
e1.cube_area()
e1.cube_volume()

r1=sphere(5)
r1.sphere_area()
r1.sphere_volume()

OUTPUT :



No comments:

Post a Comment

Write a Java program to display given extension files from a specific directory on server machine.

 DOWNLOAD     SLIP14Q2 /** * STEPS TO RUN CODE * Step 01 compile the code * Step 02 run the code * Step 03 give a file directory locatio...