0% found this document useful (0 votes)
56 views2 pages

Program

The document contains code for a Python program that uses functions to calculate the volume and area of geometric shapes like spheres and cylinders. It also contains code for a basic calculator program that uses functions to perform arithmetic operations like addition, subtraction, multiplication and division on user input numbers.

Uploaded by

anuchaitanya2017
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
56 views2 pages

Program

The document contains code for a Python program that uses functions to calculate the volume and area of geometric shapes like spheres and cylinders. It also contains code for a basic calculator program that uses functions to perform arithmetic operations like addition, subtraction, multiplication and division on user input numbers.

Uploaded by

anuchaitanya2017
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

# PROGRAM TO FIND VOLUME AND AREA OF SPHERE, CYLINDER, CUBE

from math import pi

def sphere():
r=float(input('Enter the radius:-'))

vol=4/3*pi*(pow(r,3))
s_area=4*pi*(pow(r,2))

print('Surface area of sphere:-',round(s_area,2))


print('Volume of sphere:-',round(vol,2))

def cylinder():
r=float(input('Enter the radius:-'))
h=float(input('Enter the height:-'))

l_area=2*pi*r*h
t_area=2*pi*r*h+2*pi*(r**2)
vol=pi*(pow(r,2))*h

print('Lateral Surface area of cylinder:-',round(l_area,2))


print('Total Surface area of cylinder:-',round(t_area,2))
print('Volume of cylinder:-',round(vol,2))

def cube():
s=int(input("Enter side of cube:-"))

t_area=6*s**2
vol=s**3

print('To print total surface area and volume of sphere. Enter 1')
print('To print total surface area, lateral surface area and volume of cylinder.
Enter 2')
print('To print surface area and volume of cube. Enter 3')

ent=int(input('Enter:-'))

if ent==1:
print(sphere())
elif ent==2:
print(cylinder())
elif ent==3:
print(cube())

#OUTPUT

================= RESTART: /Users/chaitanya/Desktop/py/area.py =================


To print total surface area and volume of sphere. Enter 1
To print total surface area, lateral surface area and volume of cylinder. Enter 2
To print surface area and volume of cube. Enter 3
Enter:-1
Enter the radius:-4
Surface area of sphere:- 201.06
Volume of sphere:- 268.08
None
>>>
================= RESTART: /Users/chaitanya/Desktop/py/area.py =================
To print total surface area and volume of sphere. Enter 1
To print total surface area, lateral surface area and volume of cylinder. Enter 2
To print surface area and volume of cube. Enter 3
Enter:-2
Enter the radius:-3
Enter the height:-4
Lateral Surface area of cylinder:- 75.4
Total Surface area of cylinder:- 131.95
Volume of cylinder:- 113.1
None
# PROGRAM TO FORM CALCULATOR USING FUNCTION

import math

def Add(a,b):
Sum=a+b
return Sum
def Subtract(a,b):
difference=a-b
return difference
def Multiply(a,b):
product=a*b
return product
def Divide(a,b):
quotient=a/b
return quotient
def squ(a):
sqre=a**2
return sqre
def sqrot(a):
sqroot= math.sqrt(a)
return sqroot

n1=int(input("Enter the value"))


n2=int(input("Enter the value"))
print("For add press 1","For subtract press 2","For multiply press 3","For divide
press 4","For square press 5","For square root press 6")
a=int(input("Enter what you want to do:-"))

if a==1:
print("Sum of the numbers",Add(n1,n2))
elif a==2:
print("difference of the numbers",Subtract(n1,n2))
elif a==3:
print("product of the numbers",Multiply(n1,n2))
elif a==4:
print("Dividing of the numbers",Divide(n1,n2))
elif a==5:
print("Finding the Square",n1**2)
elif a==6:
print("The square root of the number is:-",sqrot(n1))
else:
print("invalid choice")

#OUTPUT

========= RESTART: /Users/chaitanya/Desktop/py/Calculator( function).py ========


Enter the value40
Enter the value50
For add press 1 For subtract press 2 For multiply press 3 For divide press 4 For
square press 5 For square root press 6
Enter what you want to do:-1
Sum of the numbers 90
None
>>>
========= RESTART: /Users/chaitanya/Desktop/py/Calculator( function).py ========
Enter the value40
Enter the value50
For add press 1 For subtract press 2 For multiply press 3 For divide press 4 For
square press 5 For square root press 6
Enter what you want to do:-3
product of the numbers 2000
None

You might also like