Pythonfile Sana
Pythonfile Sana
Pythonfile Sana
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.
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);
Page N0.2
2. Write a programme in Python to Compute the Area of following
shades:- Circle, Triangle, Rectangle, Trapezoid, Parallelogram,
Square.
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.
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.
else:
print("it is not an isosceles triangle")
Page N0.9
7.Print multiplication table of a number input by the user.
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.
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.
Page N0.14
12.Print Geometric and Harmonic means of a series input by the user.
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.
Page N0.18
15.Determine prime numbers with in a specific range.
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.
Page N0.27
21.Determine whether a string is palindrome or not.
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
Page N0.29
Page N0.30
23.Display word after Sorting in alphabetical order.
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.
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