Practical File of Python Class 12
Practical File of Python Class 12
Secondary School
2022-2023
Computer science with python
Submitted to: Mrs. Sakshi
Submitted by:
Name: Kamal Sethi
Class: 12th Commerce
Roll no.:
Acknowledgment
I would like to express my special thanks of
gratitude to my teacher Mrs. Sakshi, who gave
me the golden opportunity to do this wonderful
practical of computer science with python for
the session 2022-23. I came to know about so
many new things in completing my practicals.
I am really thankful to them.
Secondly , I would also like to thank my
parents and friends who helped me lot in
finalizing this practical within the limited time
frame.
Kamal Sethi
12th commerce
Certificate
This is to certify that the content of the
practical for the session 2022-2023 by KAMAL
SETHI is the bonafide work of his.
Submitted to Mrs. Sakshi for consideration
in the fulfillment of the requirement of CBSE
during the year 2022-2023.
Teacher’s signature:
Program 1:
To display the elements of list twice, if it is a number and
display the element terminated with ‘*’ if it is not a number.
lst = eval(input("Enter a list :-"))
for i in lst :
if i.isdigit() :
print(i*2)
elif i.isalpha() :
print(i+"#")
OUTPUT:
Enter a list :-['kamal']
kamal#
Enter a list :-['23']
2323
Program 2:
To create a function chkOdd() that takes one argument(a
positive integer)and reports if the argument is odd or not.
def chkOdd(x):
if x%2==0:
return "even"
else :
return "Odd"
a = int (input ("Enter the positive number :- "))
print(chkOdd(a))
OUTPUT:
Enter the positive number :- 568
even
Program 3:
Write the definition of the function Fending(SCORES) to find the
sum of numbers ending with 4. The numbers are stored in the
list SCORES
def Fending(SCORES):
Fending=0
for i in l:
if i%10==4:
Fending+=i
return Fending
l=[44,64,69]
s=Fending(l)
print(s)
OUTPUT:
108
Program 4:
Write the definition of a function SumE(L),which should find the sum of
even numbers of the list.For example, if L=[21,22,12,5,8,6,90], output
should be 138
def SumE(L):
S=0
for n in L:
if n%2 == 0:
S+=n
return S
number=[20,22,3,42,29,38]
s=SumE(number)
print(s)
OUTPUT:
122
Program 5:
To create A to E pattern with one character increased in every
next line using nested for loop.
n=5
for i in range(n):
t=65
for j in range(i+1):
print(chr(t),end='')
t+=1
print()
OUTPUT:
A
AB
ABC
ABCD
ABCDE
Program 6:
Read a text file line by line and display each word separatedby a
“#”
f =open("E:\\file.txt",'r')
item=[]
for line in f:
words=line.split()
for i in words:
item.append(i)
print('#'.join(item))
OUTPUT:
hello#the#python#is#working#great
now#its#the#time#to#do#practical#work
Program 7:
Read a text file and display the number of
vowels/consonants/uppercase/lowercase
characters in the file.
f=open("e:\\file.txt","r")
vow=con=up=low=0
a=f.read()
for i in a:
if i.isalpha():
if i in["a","e","i","o","u","A","E","I","O","U"]:
vow+=1
else:
con+=1
if i.isupper():
up+=1
elif i.islower():
low+=1
print("no of vowels",vow)
print("no of consonants",con)
print("no of
uppercase",up)
print("no of
lowercase",low)
f.close()
OUTPUT :
no of vowels 20
no of
consona
nts 38no
of
uppercas
e 0 no of
lowercas
e 58
Program 8:
Remove all the lines that contain the character 'a' ina file and write it
to another file.
f=open("c:\users\documents\character.txt",'r')
file=open("c:\users\documents\character.txt",'w')
l=f.readlines()
for i in l:
if a‟ not in i:
file.write()i
file.close()
f.close()
Output:
List of following input
Number of lists
f=open("E:\\stock.txt","wb+")
a={}
found=False
for i in range(5):
a["roll"]=roll
a["name"]=name
pickle.dump(a,f)
f.seek(0)
try:
while True:
b=pickle.load(f)
if b ["roll"]==c:
print(b)
found=True
except EOFError:
if found:
f.close()
else:
f.close()
OUTPUT:
enter the roll no.:1
import random
a="y"
while a=="y":
print("random number",random.randint(1,6))
OUTPUT:
random number 5
stack.append("four")
stack.append("Five")
print("pop 1",stack.pop())
OUTPUT:
elements in stack ['one', 'two', 'three', 'four', 'Five']
pop 1 Five
pop 2 four
OUTPUT:
Program 14:
Write a program to implement various functions of math
module.
import math
OUTPUT:
The square root of 64 is : 8.0
The floor value of 2.7 is : 2
The ceil value of 4.5 is : 5
The factorial of 6 is : 720
Program 15:
Write a program to check whether a string is palindrome or
not.
def ispalindrome(s):
return s== s[: :-1]
if ans:
print("YES")
else:
print("NO")
OUTPUT:
OUTPUT:
Enter a number: 7
The factorial of 7 is 5040
Program 17:
Write a program to connect with database, insert
records into table and display all records.
#connection with database and inserting a value –
#display records
Program 20:
Write a program to delete a record from the table by
importing suitable module.
:
Program 18:
Write a program to search a particular record by
importing suitable module.If not found,display
appropriate message.
OUTPUT:
Program 19:
Write a program to update a particular record. If not
found,display appropriate message.
OUTPUT:
Program 21:
Create a table and insert data into it , describe the table and show distinct
cities from table.
Program 22:
Create a table and do the following commands:
1.Display the record of those persons whose name begins with k.
2. Insert a new column marks.
3. Update the marks from 194 to 200 .
4. Display the names of those student who have scored below 75.
Program 23:
Create two tables and do the following commands:
1. To display the frequency of employees department wise.
2. To display names of employees, sales and qualification who have achieved sales more
than 20000.
3. To change the basic salary of employees whose depid is 103.
4. To delete the bonus column.
5. To find the max sales.
Program 24:
Create two tables and do the following commands:
1. Add a new column co partnership.
2. Show the records of those employees who have “h” in their name.
3. Arrange the data in descending order.
4. Find average extra time salary.
5. Display distinct qualification from employees.
Program 25:
Create two tables and do the following commands:
1. To list the books name of market type.
2. To increase the price of books with fiction type.
3. To insert a new row in the table issued having the following data :”19022”,22.
4. To display the bookid,bookname for all books which have been issued(query will
require contents from both the tables).
5. Remove the table issued.
Index
s.no Date Topic Teachers
sign
1. 28/04/2022 To display the elements of list twice, if it is a number
and display the element terminated with ‘*’ if it is not
a number.
6. 13/05/2022 Read a text file line by line and display each word
separated by a #.
8. 21/05/2022 Remove all the lines that contain the character 'a' in a
file and write it to another file.
27/05/2022 Create a binary file with name and roll number. Search
9. for a given roll number and display the name, if not
found display appropriate message.
10. 4/07/2022 Create a binary file with roll number, name and marks.
Input a roll number and update the marks.
11. 7/07/2022 Write a random number generator that generates
random numbers between 1 and 6 (simulates a dice).
21. 26/10/2022 Create a table and insert data into it , describe the
table and show distinct cities from table.