0% found this document useful (0 votes)
10 views3 pages

Python Functions for Math Operations

Uploaded by

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

Python Functions for Math Operations

Uploaded by

vishnupriyapacet
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as ODT, PDF, TXT or read online on Scribd

5:Implementing programs using Functions.

(Factorial,
largest number in a list, area of shape)

(a):Factorial

def fact(n):
if(n==0):
return 1
else:
return(n*fact(n-1))
n=int(input("Enter Number : "))
f=fact(n)
print("Factorial of",n,"is",f)

Output:

Enter Number : 10
Factorial of 10 is 3628800

(b):Largest Number in List

def largest_num(l):
return max(l)
l1 = eval(input("Enter a List of numbers separated by comma : "))
print("Largest number in given List = ", largest_num(l1))
Output:
Enter a List of numbers separated by comma : 67,89,34
Largest number in given List = 89

(c):Area of Shapes

def square(s):
area=s*s
return area
def rectangle(l,b):
area=l*b
return area
def circle(r):
area=3.14*r*r
return area
def triangle(base,height):
area=0.5*base*height
return area
s=int(input("Enter the side of the Square is:"))
print("Area of Square is:",square(s))
l=int(input("Enter the length of the Rectangle:"))
b=int(input("Enter the breadth of the Rectangle:"))
print("The Area of Rectangle is:",rectangle(l,b))
r=float(input("Enter the radius of the circle:"))
print("The Area of Circle is:",circle(r))
base=int(input("Enter the Base of the Triangle:"))
height=int(input("Enter the Height of the Triangle:"))
print("The Area of Triangle is:",triangle(base,height))
Output:

Enter the side of the Square is:4


Area of Square is: 16
Enter the length of the Rectangle:4
Enter the breadth of the Rectangle:5
The Area of Rectangle is: 20
Enter the radius of the circle:6
The Area of Circle is: 113.03999999999999
Enter the Base of the Triangle:4
Enter the Height of the Triangle:8
The Area of Triangle is: 16.0

You might also like