Slip 6 - A) Write python script using package to calculate area and volume of cube and sphere

Solution:

Pacakge Calc

pi=3.14
def area_sphere(r):
    global pi
    return 4*pi*r*r

def vol_sphere(r):
    global pi
    return 4/3*pi*(r*r*r)

def area_cube(s):
    return 6*s*s

def vol_cube(s):
    return s*s*s

Main code

from Calc import functions

radius=int(input("Enter radius of sphere: "))
sphere_area=functions.area_sphere(radius)
sphere_vol=functions.vol_sphere(radius)
print(f"Area of sphere: {sphere_area}\nVolume of sphere: {sphere_vol}\n\n")
side=int(input("Enter side of cube: "))
cube_area=functions.area_cube(side)
cube_vol=functions.vol_cube(side)
print(f"Area of cube: {cube_area}\nVolume of cube:{cube_vol}")

Output:


Output pic


Post a Comment

0 Comments