Find the area of Rectangle.
length = 10
breadth = 20
print('length = ', length, 'Breadth = ', breadth)
area = length * breadth
print('Area of rectangle is = ', area)
Page N0.1
1. Write a programme in Python to Compute Sum, Subtraction,
Multiplication, Division, and Exponent of variables input by the user.
A = input("Enter first number: ");
B = input("Enter Second number: ");
C = int(A) + int(B);
D = int(A) - int(B);
E = int(A) * int(B);
F = int(A) / int(B);
G = int(A)**int(B);
print("The sum is: ",C);
print("The Subtraction is: ",D);
print("The multiplication is: ",E);
print("The division is: ",F);
print("The exponent is: ",G);
Page N0.2
2. Write a programme in Python to Compute the Area of following
shades:- Circle, Triangle, Rectangle, Trapezoid, Parallelogram,
Square.
print("Welcome to area Calculator")
SCALP=input("Press 1 forSquare\n 2 for Triangle\n 3 for Rectangle\n 4 for Circle\n")
if SCALP=='1':
area=int(input(" Enter the area\n"))
area_square=area*area
print("Area of Square=" +str(area_square))
elif SCALP=='2':
a1=float(input("Enter first side\n"))
a2=float(input("Enter second side\n"))
a3=float(input("Enter third side\n"))
aot=(a1+a2+a3)/2
triangle_area=(aot - a1)*(aot - 2)*(aot - 3)**0.5
print("Area of triangle is %0.2f" % triangle_area)
elif SCALP=='3':
w=int(inputt("Enter Width\n"))
l=int(input("Enter Length\n"))
area_rec=w*l
print("Area of Rectangle",area_rec)
elif SCALP=='4':
import math
r=float(input("Enter the radius of Circle\n"))
area_cir=math.pi*r*r
print("Area of circle %0.2f" % area_cir)
else:
print("ERROR")
Page N0.3
Page N0.4
3. Write a programme in Python to Compute the Volume of following
shades:- Cylinder, Cube, Cone, Sphere.
import math
pi=math.pi
print("SHAPES")
print("1. Cube")
print("2. Cylinder")
print("3. Cone")
print("4 Sphere")
print("enter your choice to calculate volume from above")
n=int(input())
if n==1:
r1=int(input("enter radius:"))
v1=r1*r1*r1
print("volume of Cube:",round(v1,3))
elif n==2:
r2=int(input("enter radius:"))
h2=int(input("enter height:"))
v2=pi*r2*r2*h2
print("volume of Cylinder:",round(v2,3))
elif n==3:
r3=int(input("enter radius:"))
h3=int(input("enter height:"))
v3=(1/3)*pi*r3*r3*h3
print("volume of Cone:",round(v3,3))
elif n==4:
r4=int(input("enter radius:"))
v4=(4/3)*pi*r4*r4*r4
print("volume of Sphere:",round(v4,3))
Page N0.5
Page N0.6
4.Compute the print roots of quadratic equation ax2+bx+c=0, where the value of a, b
and c are input by the user.
A=int(input("Enter First Number:"))
B=int(input("Enter Second Number:"))
C=int(input("Enter Third Number:"))
x=((B)+(B**2-(4*A*C))**0.5)/2*A
y=((B)-(B**2-(4*A*C))**0.5)/2*A
print(x)
print(y)
Page N0.7
5.Print number up to N which are not divisible by 3, 6, 9 , e.g.,1, 2, 4, 5, 7,…
n=int(input("enter n:"))
print("the number from 1 to ",n)
print("not div by 3,6,9 ")
for i in range(1,n+1):
if i%3!=0:
print(i,end=" , ")
Page N0.8
6.Write a program in Python to determine in whether a triangle is isosceles
or not.
A=input("Enter first value:")
B=input("Enter second value:")
C=input("Enter third value:")
if A==B or A==C or B==C:
print("it is iscsceles triangle")
else:
print("it is not an isosceles triangle")
Page N0.9
7.Print multiplication table of a number input by the user.
n=int(input("enter number for multiplication table:"))
for i in range(1,11):
print(n,'x',i,'=',n*i)
Page N0.10
8.Compute sum of natural numbers from 1 to n numbers.
sum=0
n=int(input("enter any integer value:"))
if n>0:
for i in range(1,n+1):
sum+sum+i
print("sum of the numbers from 1 to",n,":",sum)
elif n==0:
print("sum=0")
else:
print("please enter positive value")
Page N0.11
9.Print Fibonacci series up to n numbers e.g. 0 1 1 2 3 5 8 13 ……n.
a=int(input("1st no of fib series:"))
b=int(input("2nd no of fib series:"))
n=int(input("count:"))
print("fibonacci series:")
print(a,end=",")
print(b,end=",")
for i in range(1,n-1):
c=a+b
print(c,end=',')
a=b
b=c
Page N0.12
10.Compute factorial of a given number.
def fact(n):
fact=1
for i in range(1,n+1):
fact=fact*i
print("fact:",fact)
num=int(input("enter n:"))
if num<0:
print("fact of-ve no is not possible")
elif num==0:
print("fact of o is 1")
else:
fact(num)
Page N0.13
11.Count occurrence of a digit 5 in a given integer number input by the
user.
n=int(input("Enter an integer value:"))
n=str(n)
print("count of 5:",n.count("5"))
Page N0.14
12.Print Geometric and Harmonic means of a series input by the user.
a=int(input('enter first number'))
b=int(input('enter second number'))
GM=(a*b)**0.5
HM=(2*a*b)/(a+b)
print('geometric mean of',a, 'and',b,'=',GM)
print('harmonic mean of',a,'and',b,'=',HM)
Page N0.15
13.Evaluate the following expressions:
a.x-x2/2!+x3/3!-x4/4!+…xn/n!
b.x-x3/3!+x5/5!-x7/7!+…xn/n!
def fact(m):
if m==0:
return 1
else:
return m*fact(m-1)
s=0
x=int(input("enter x:"))
n=int(input("enter n:"))
for i in range(1,n+1):
k=2*i-1
s=s+((-1)**(i+1))*((x**k)/fact(k))
print("sum of the series:",round(s,3))
Page N0.16
Page N0.17
14.Print all possible combinations of 4,5, and 6.
num1=int(input("enter the first number:"))
num2=int(input("enter the second number:"))
num3=int(input("enter the third number:"))
num_list=[]
num_list.append(num1)
num_list.append(num2)
num_list.append(num2)
for i in range(0,3):
for j in range(0,3):
for k in range(0,3):
if(i!=j & j !=k & k !=i):
print("[{} {} {}]".format(num_list[i],num_list[i],num_list[k]))
Page N0.18
15.Determine prime numbers with in a specific range.
m=int(input("enter initial value:"))
n=int(input("enter terminating value:"))
if m<n:
for i in range(m,n+1):
if i>1:
for j in range(2,i):
if i%j==0:
break
else:
print(i,end=",")
elif m>n:
for i in ranmge(m,n,-1):
if i>1:
for j in range(2,i):
if i%j==0:
break
else:
pring(i,end==",")
else:
print("..oh both the values are equal..")
print("..kindly enter different values..")
Page N0.19
Page N0.20
16.Count number of persons of age above 60 and below 90.
n=int(input("number of persons:"))
print("enter ages of",n,"persons")
a=[]
for i in range(n):
a.append(int(input()))
print("ages:")
for i in range(n):
if a[i]<=0:
print("na",end=",")
else:
print(a[i],end=",")
print()
c=0
for i in a:
if i>=60 and i<= 90:
c=c+1
print("persons between 60 and 90 are:")
print(c)
Page N0.21
Page N0.22
17. Compute transpose of matrix.
r=int(input("rows:"))
c=int(input("columns:"))
print("enter elements:")
a=[]
for i in range(r):
b=[]
for j in range(c):
b.append(int(input()))
a.append(b)
print("matrix is:")
for i in range(r):
for j in range(c):
print(a[i][j],end="")
print()
print("transpose of the matrix is:")
for i in range(r):
for j in range(c):
print(a[j][i],end="")
print()
Page N0.23
Page N0.24
18.Perform following operations on two matrices.
1) Addition 2) Subtraction 3) Multiplication
import numpy
x = numpy.array([[1, 2], [4, 5]])
y = numpy.array([[7, 8], [9, 10]])
print ("The element wise addition of matrix is : ")
print (numpy.add(x,y))
print ("The element wise subtraction of matrix is : ")
print (numpy.subtract(x,y))
print ("The element wise multiplication of matrix is : ")
print (numpy.multiply(x,y))
Page N0.25
19.Count occurrence of vowels.
string=input("Enter string:")
vowels=0
for i in string:
if(i=='a' or i=='e' or i=='i' or i=='o' or i=='u' or i=='A' or i=='E' or i=='T' or i=='O' or
i=='U'):
vowels=vowels+1
print("number of vowels are:",string)
print(vowels)
Page N0.26
20.Count total number of vowels in a word.
str=str(input("enter any string:"))
str=str.lower()
c={}
search="aeiou"
for i in search:
n=str.count(i)
c[i]=n
print(c)
m=c.values()
tv=sum(m)
print("total vowels:",tv)
Page N0.27
21.Determine whether a string is palindrome or not.
str=str(input("enter any string:"))
print("entered string is:",str)
rev=str[::-1]
print("reverse string is:",rev)
if str==rev:
print("reverse string is palindrome")
else:
print("entered string is not a palindrome")
Page N0.28
22.Perform following operations on a list of numbers:
1) Insert an element 2) delete an element 3) sort the list 40 delete entire list
n=int(input("enter how many elements you want in the list:"))
if n>0:
print("data is appropriate")
print("enter",n,"elements")
LIST=[]
for i in range(n):
LIST.append(input())
print("LIST is:",LIST)
a=int(input("insert an element in the LIST:"))
a=str(a)
b=int(input("index at which u would like to insert the element:"))
LIST.insert(b,a)
print("after inserting new element the LIST is:")
print(LIST)
c=str(input("element you want to delete:"))
LIST.remove(c)
print("after deletion the new list is:")
print(LIST)
s1=list(map(int,LIST))
s1.sort()
print("sorted LIST is:")
print(s1)
s1.clear()
print("after deleting all the element from the list:")
print(s1)
else:
print("kindly re-enter the value of n")
Page N0.29
Page N0.30
23.Display word after Sorting in alphabetical order.
str=str(input("enter any string:"))
print("entered string is:",str)
print("sorted list is:")
str=sorted(str)
str1=""
print("string in sorted form is:")
print(str1.join(str))
Page N0.31
24.Perform sequential search on a list of given numbers.
def fun(list,key):
for i in range(len(list)):
if list[i]==key:
return i
break
return-1
list=[2,3,1,4,5,7]
print("list is:",list)
key=int(input("the no.you want to search:"))
n=fun(list,key)
if n!=-1:
print(key,"is found at position",n+1)
else:
print("data is not present in the list")
Page N0.32
25.Perform sequential search on ordered list of given numbers.
def fl(l,key):
for i in range(len(l)):
if l[i]==key:
return i
break
return-1
n=int(input("enter count:"))
if n>0:
print("data is appropriate")
print("enter",n,"elements")
l=[]
for i in range(n):
l.append(input())
print("list is:",l)
else:
print("kindly re-enter the value of n")
nl=list(map(int,l))
print("list in integer form:")
print(nl)
nl.sort()
print("sorted list is:")
print(nl)
key=int(input("the number you want to search:"))
n=fl(nl,key)
if n!=-1:
print(key,"is found at location",n+1)
else:
print("element is not in the list")
Page N0.33
Page N0.34
26.Maintain practical notebook as per their serial numbers in library using
Python dictionary.
from collections import OrderedDict
dl={}
dl[5]="compute factorial of given number."
dl[1]="print all possible combinations of 4,5,6."
dl[4]="compute transpose of matrix."
dl[3]="count occurance of vowels."
dl[2]="count total numbers of vowels in a word."
dl[6]="determine wheather a string is palindrome or not."
d=OrderedDict(sorted(dl.items()))
for i,j in d.items():
print("program numbers:",i,":",j)
print()
Page N0.35
27. Perform following operations on dictionary
1) Insert 2) delete 3) change
a={}
print("empty dict a:",a)
print("type of a:",type(a))
a={"1":"ABC","2":"DEF"}
print("dict a with element is:",a)
print(a.keys())
print(a.values())
print(a.items())
a['3']="NEW"
print("after adding new element")
print("dict a is:",a)
a['1']="EDIT"
print("after editing the new dict is")
print(a)
a.pop("1")
print("after deleting the first element")
print("dict is:",a)
a.clear()
print("after deleting all the element")
print("the dict is:",a)
Page N0.36
Page N0.37