Saitanuj Practical Record Book

You might also like

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 25

JAIN HERITAGE SCHOOL

Python Practical Record Book


Grade 11 Commerce(2022-23)

Submitted By:
SAITANUJ.B

Submitted To:
Sheethal Ravindran
INDEX
S.No TOPIC Pg.No Signature
01 PROGRAM TO SWAP TWO NUMBERS
02 PROGRAM TO FIND AREA OF TRIANGLE AND
RECTANGLE
03 PROGRAM TO CHECK IF NUMBER IS ODD OR
EVEN
04 PROGRAM TO CHECK IF NUMBER IS

Page |1
POSITIVE,NEGATIVE OR ZERO
05 PROGRAM TO FIND TOTAL AND AVERAGE
MARKS OF A STUDENT
06 PROGRAM TO FIND SUM OF N NATURAL
NUMBERS
07 PROGRAM TO FIND EVEN NUMBERS IN A
GIVEN RANGE
08 PROGRAM TO FIND FACTORIAL OF A
NUMBER
09 PROGRAM TO FIND FIBANOCCI SERIES OF A
NUMBER
10 PROGRAM TO FIND SUM OF A DIGIT AND
REVERSE OF A NUMBER
11 PROGRAM TO FIND ARMSTRONG AND
PALLIANDROME
12 PROGRAM TO FIND THE GREATEST OF TWO
NUMBERS
13 PROGRAM TO READ A LINE AND PRINT
IT’STATISTICS
14 PROGRAM TO FIND FREQUENCY COUNT OF
ELEMENT IN A LIST
15 PROGRAM TO SEARCH FOR A ELEMENT
16 PROGRAM TO CREATE A TUPLE
17 PROGRAM TO CREATE A DICTIONARY

PROGRAM-1
SWAPPING

AIM:
Program to swap two numbers.

Page |2
SOURCE CODE:
a=int(input("enter the value for a"))
b=int(input("enter the value for b"))
temp=a
a=b
b=temp
print("after swapping a and b value is",a,b)

OUTPUT:
enter the value for a3
enter the value for b6
after swapping a and b value is 6 3

PROGRAM-2
AREA OF TRIANGLE AND RECTANGLE

AIM:
Program to find area of triangle and rectangle.

Page |3
SOURCE CODE:
while True:
print("In menu In")
print("1.area of triangle/n2.area of rectangle/n")
ch=int(input("enter your choice"))
if ch==1:
a=int(input("enter the sides of triangle"))
b=int(input("enter the base of triangle"))
h=int(input("enter the height of triangle"))
ar=0.5*b*h
print("area of triangle",ar)
elif ch==2:
l=int(input("enter the values of l"))
b=int(input("enter the value of b"))
ar=l*b
print("area of rectangle",ar)
op=input("Do you want to continue?<y/n>")
if op=='n':
break

OUTPUT:
In menu In
1.area of triangle/n2.area of rectangle/n
enter your choice1

Page |4
enter the sides of triangle3
enter the base of triangle6
enter the height of triangle9
area of triangle 27.0
Do you want to continue?<y/n>y
In menu In
1.area of triangle/n2.area of rectangle/n
enter your choice2
enter the values of l36
enter the value of b39
area of rectangle 1404
Do you want to continue?<y/n>n

PROGRAM-3
ODD OR EVEN

AIM:
Program to check whether a number is odd or even.

Page |5
SOURCE CODE:
n=int(input("enter the number"))
if n%2==0:
print(n,"is even number")
else:
print(n,"is odd number")

OUTPUT:
enter the number6
6 is even number

PROGRAM-4
POSITIVE, NEGATIVE OR ZERO

AIM:
Program to check whether a number is positive, negative or zero

Page |6
SOURCE CODE:
n=int(input("enter the number"))
if n>0:
print(n,"is positive")
elif n==0:
print(n,"is equal to zero")
else:
print(n,"is negative")

OUTPUT:
enter the number-3
-3 is negative

PROGRAM-5
TOTAL AND AVERAGE MARKS OF A STUDENT

AIM:
Program to find total and average marks of a student in 5 subjects.

Page |7
SOURCE CODE:
m1=int(input("enter the number"))
m2=int(input("enter the number"))
m3=int(input("enter the number"))
m4=int(input("enter the number"))
m5=int(input("enter the number"))
T=m1+m2+m3+m4+m5
av=T/5
print("the total marks is",T)
print("the average marks is",av)
if av>90 and av<100:
print("grade A*")
elif av>80 and av<90:
print("grade A")
elif av>70 and av<80:
print("grade B*")
elif av>60 and av<70:
print("grade B")
elif av>50 and av<60:
print("grade C*")
elif av>40 and av<50:
print("grade C")
elif av>30 and av<40:
print("grade D")
else:
print("Fail")

OUTPUT:
enter the number93

Page |8
enter the number90
enter the number95
enter the number96
enter the number98
the total marks is 472
the average marks is 94.4
grade A*

PROGRAM-6
SUM OF N NATURAL NUMBERS

AIM:
Program to find sum of n natural numbers.

Page |9
SOURCE CODE:
sum=0
n=int(input("enter the value"))
for i in range(0,n):
sum=sum+i
print("sum is",sum)

OUTPUT:
enter the value99
sum is 4851

PROGRAM-7
EVEN NUMBERS IN A GIVEN RANGE

AIM:
Program to find all even numbers in a given range.

P a g e | 10
SOURCE CODE:
n=int(input("enter the value"))
for i in range(0,n,2):
print(i)

OUTPUT:
enter the value6
0
2
4

PROGRAM-8
FACTORIAL OF A NUMBER

AIM:
Program to find the factorial of a number.

P a g e | 11
SOURCE CODE:
i=1
n=int(input("enter the value"))
f=1
while i<n:
f=f*i
i+=1
print(f)

OUTPUT:
enter the value6
120

PROGRAM-9
FIBANOCCI SERIES OF A NUMBER

AIM:
Program to find fibanocci series of a number.

P a g e | 12
SOURCE CODE:
n=int(input("enter the value"))
a=0
b=1
print("fibanocci series is")
print(a,b)
for i in range(2,n):
f=a+b
print(f)
a=b
b=f

OUTPUT:
enter the value6
fibanocci series is
01
1
2
3
5

PROGRAM-10
SUM OF DIGIT AND REVERSE OF A NUMBER

AIM:
Program to find sum of digit and reverse of a number.

P a g e | 13
SOURCE CODE:
while True:
print("In menu In")
print("1.sum of digits/n2.reverse of a number/n")
ch=int(input("enter your choice"))
if ch==1:
n=int(input("enter the number"))
m=n
S=0
while(n>0):
a=n%10
S=S+a
n=n//10
print("Sum of digits of",n,"is",S)
elif ch==2:
n=int(input("enter the number"))
m=n
S=0
while(n>0):
a=n%10
S=S*10+a
n=n//10
print("Reverse of",n,"is",S)
op=input("Do you want to continue?<y/n>")
if op=='n':
break

OUTPUT:
In menu In

P a g e | 14
1.sum of digits/n2.reverse of a number/n
enter your choice1
enter the number6
Sum of digits of 0 is 6
Do you want to continue?<y/n>y
In menu In
1.sum of digits/n2.reverse of a number/n
enter your choice2
enter the number36
Reverse of 0 is 63
Do you want to continue?<y/n>n

PROGRAM-11
ARMSTRONG AND PALIANDROME

AIM:
Program to find Armstrong and paliandrome.

P a g e | 15
SOURCE CODE:
while True:
print("In menu In")
print("1.armstrong/n2.paliandrome/n")
ch=int(input("enter your choice"))
if ch==1:
n=int(input("enter the number"))
m=n
S=0
while(n>0):
a=n%10
S=S+a*a*a
n=n//10
if m==S:
print(m,"is armstrong")
else:
print(m,"is not armstrong")
elif ch==2:
n=int(input("enter the number"))
m=n
S=0
while(n>0):
a=n%10
S=S*10+a
n=n//10
if m==s:
print(m,"is paliandrome")
else:

P a g e | 16
print(m,"is not paliandrome")
op=input("Do you want to continue?<y/n>")
if op=='n':
break

OUTPUT:
In menu In
1.armstrong/n2.paliandrome/n
enter your choice1
enter the number153
153 is armstrong
Do you want to continue?<y/n>y
In menu In
1.armstrong/n2.paliandrome/n
enter your choice2
enter the number101
101 is paliandrome
Do you want to continue?<y/n>n

PROGRAM-12
GREATEST OF TWO NUMBERS

AIM:

P a g e | 17
Program to find greatest of two numbers.

SOURCE CODE:
a=int(input("enter the value"))
b=int(input("enter the value"))
if a>b:
print(a,"is greater")
else:
print(b,"is greater")

OUTPUT:
enter the value3
enter the value6
6 is greater

PROGRAM-13
READ A LINE AND PRINT IT’S STATISTICS

AIM:

P a g e | 18
Program to read a line and print it’s statistics.

SOURCE CODE:
st1=input("enter the string")
U=L=d=a=sp=0
for i in st1:
if i.isupper():
U+=1
elif i.islower():
L+=1
elif i.isdigit():
d+=1
if i.isalpha():
a+=1
elif i.isspace():
sp+=1
print("number of upper case",U)
print("number of lower case",L)
print("number of digits",d)
print("number of alphabets",a)
print("number of spaces",sp)

OUTPUT:
enter the stringMy NAME is Pranav i am 17 years Old
number of upper case 7

P a g e | 19
number of lower case 18
number of digits 2
number of alphabets 25
number of spaces 8

PROGRAM-14
FREQUENCY COUNT OF ELEMENTS IN A LIST

P a g e | 20
AIM:
Program to count frequency of given elements in a list of numbers.

SOURCE CODE:
lst=eval(input("enter the list"))
length=len(lst)
element=int(input("enter the element"))
count=0
for i in range(0,length):
if element==lst[i]:
count+=1
if count==0:
print(element,"not present in the list")
else:
print(element,"is present with the frequency count",count)

OUTPUT:
enter the list3,6,9
enter the element6
6 is present with the frequency count 1

PROGRAM-15
SEARCHING FOR A ELEMENT

P a g e | 21
AIM:
Program to search for an element in a given list of numbers.

SOURCE CODE:
L=[]
n=int(input("enter the limit"))
for i in range(0,n):
val=input("enter the element")
L.append(val)
Selement=int(input("enter the search element"))
for i in range(0,n):
if L[i]==Selement:
print("element is presentat",i)
break
else:
print("element not present")

OUTPUT:
enter the limit5
enter the element3
enter the element4
enter the element3
enter the element5
enter the element4
enter the search element5
element not present

PROGRAM-16
TUPLE

P a g e | 22
AIM:
Program to input “n” number of students in a tuple and print the tuple in ascending order.

SOURCE CODE:
name=()
print("How many names do you want to enter:")
n=int(input())
ctr=1
if n>0:
while ctr<=n:
print("enter the name")
Mname=input()
name=name+(Mname,)
ctr+=1
print("original name list",name)
Sname=sorted(name)
print(Sname)

OUTPUT:
How many names do you want to enter:
3
enter the name
rajhas
original name list ('rajhas',)
['rajhas']
enter the name
adwaith
original name list ('rajhas', 'adwaith')
['adwaith', 'rajhas']

P a g e | 23
enter the name
pranav
original name list ('rajhas', 'adwaith', 'pranav')
['adwaith', 'pranav', 'rajhas']

PROGRAM-17
DICTIONARY
AIM:

P a g e | 24
Program to create a dictionary containing the names of the winners as keys and the number of competitions won
as value.

SOURCE CODE:
n=int(input("enter the number of students:"))
winner={}
for i in range(n):
key=input("enter the name of the student")
value=int(input("enter number of competitions won:"))
winner[key]=value
print("the dictionary is",winner)

OUTPUT:
enter the number of students:3
enter the name of the studentakash
enter number of competitions won:2
the dictionary is {'akash': 2}
enter the name of the studentrajesh
enter number of competitions won:3
the dictionary is {'akash': 2, 'rajesh': 3}
enter the name of the studentprem
enter number of competitions won:4
the dictionary is {'akash': 2, 'rajesh': 3, 'prem': 4}

P a g e | 25

You might also like