Python Programming Lab 5
Python Programming Lab 5
(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
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: