Professional Documents
Culture Documents
Cs Print
Cs Print
CLASS – 12TH – A
ROLL NO. – 11
SCHOOL – kendriya
Vidyalaya sainik vihar
COMPUTER SCIENCE PRACTICAL LIST FOR CLASS XII
1. Write a python program to search an element in a list and display the frequency of element
present in list and their location using Linear search by using user defined function. [List and
search element should be entered by user]
2. Write a python program to search an element in a list and display the frequency of element
present in list and their location using binary search by using user defined function. [List and
search element should be entered by user]
3. Write a python program to pass list to a function and double the odd values and half even
values of a list and display list element after changing.
4. Write a Python program input n numbers in tuple and pass it to function to count how many
even and odd numbers are entered.
5. Write a Python program to function with key and value, and update value at that key in
dictionary entered by user.
6. Write a Python program to pass a string to a function and count how many vowels present in
the string.
10. Write a python program to read and display file content line by line with each word separated
by #.
11. Write a python program to remove all the lines that contain the character ‘a’ in a file and write
it to another file.
12. Write a python program to read characters from keyboard one by one, all lower case letters
gets stored inside a file “LOWER”, all uppercase letters gets stored inside a file “UPPER”, and all
other characters get stored inside “OTHERS”
13. Write a python program to create a binary file with name and roll number. Search for a given
roll number and display name, if not found display appropriate message.
14. Write a python program to create a binary file with roll number, name and marks, input a roll
number and update the marks.
15. Write a python program to create a CSV file with empid, name and mobile no. and search
empid, update the record and display the records.
16. Write a Python program to create Lpush( ) and Lpop( ) function to do push and pop operation
on a stack using a list e.g. take a student information and push and pop the details.
17. Create a student table and insert data. Implement the following SQL commands on the student
table:
ALTER table to add new attributes / modify data type / drop attribute
UPDATE table to modify data ORDER By to display data in ascending / descending order
DELETE to remove tuple(s) GROUP BY and find the min, max, sum, count and average
18. Integrate SQL with Python by importing the MySQL module record of employee and display the
record.
19. Integrate SQL with Python by importing the MySQL module to search an employee using
empno and if present in table display the record, if not display appropriate method.
20. Integrate SQL with Python by importing the MySQL module to search a student using rollno,
update the record.
21. Integrate SQL with Python by importing the MySQL module to search a student using rollno,
delete the record.
22. Take a sample of ten phishing e-mails (or any text file) and find most commonly occurring
word(s)
PRACTICAL- 1
INPUT
OUTPUT
PRACTICAL- 2
INPUT
OUTPUT
AIM- Write a program to pass list to a function and double the odd
values and half even values of a list and display list element
after changing
SOFTWARE USED- IDLE (PYTHON 3.10 64-bit)
INPUT
OUTPUT
INPUT
OUTPUT
AIM- Write a program to function with key and value, and update value at that
key in dictionary entered by user
INPUT
OUTPUT
INPUT
OUTPUT
INPUT
OUTPUT(S)
INPUT
OUTPUT(S)
= RESTART: C:\Python310\deepak.py
Choose which function to use:
1. Square root (sqrt)
2. Factorial
3. Power
4. Log
Trigonometric functions:
5. sin
6. cos
7. tan
Value of Constants:
8. e
9. pi
10. tau
Enter operation number: 4
Enter a number: 20
Enter base: 10
1.301029995663981
= RESTART: C:\Python310\deepak.py
Choose which function to use:
1. Square root (sqrt)
2. Factorial
3. Power
4. Log
Trigonometric functions:
5. sin
6. cos
7. tan
Value of Constants:
8. e
9. pi
10. tau
Enter operation number: 3
Enter a number: 2
Enter power: 5
32.0
PRACTICAL- 9
INPUT
OUTPUT
AIM- Write a program to read and display file content line by line
with each word separated by #.
SOFTWARE USED- IDLE (PYTHON 3.10 64-BIT)
INPUT
#TO READ AND DISPLAY FILE CONTENT LINE BY LINE WITH EACH WORD SEPARATED BY #
a= open ("TEXT. Txt ","r")
lines a. readlines ()
for line in lines:
x=line. Split ()
for y in x:
print (y+"#", end = “ ” )
print (" ")
OUTPUT
AIM- Write a program to remove all the lines that contain the
character ‘a’ in a file and write it to another file.
SOFTWARE USED- IDLE (PYTHON 3.10 64-BIT)
INPUT
file=open (“TEXT1. txt","r")
lines=file. readlines ()
file.close()
file=open ( TEXT1.txt", "W")
file=open ( MODTEXT1.txt", "W")
for line in lines:
if 'a' in line :
filel.write(line)
else:
file.write (line)
print ("Lines that contain a character are removed from TEXT1")
print ("Lines that contain a character are added in MODTEXT1 ")
file.close()
file1.close()
OUTPUT
PRACTICAL- 12
INPUT
AIM- Write a program to create a binary file with name and roll number.
search for a given roll number and display name, if not found display
appropriate
INPUT
#CREATE A BINARY FILE WITH NAME & ROLL NUMBER. SEARCH FOR A GIVEN ROLL NUMBER AND DISPLAY NME, IF NOT
FOUND DISPLAY APPROPRIATE MESSAGE
import pickle
s data= {}
s list= []
totals =int (input ("Enter number of students:”))
for i in range (totals):
s data [ "Roll no."] =int (input ("Enter roll no. :))
s data ["Name"] = input ("Enter name:")
s list. Append (s data)
s data= {}
a= open ("TEXT2.dat", "b")
pickle. dump (s list, a)
a. Close ()
OUTPUT
AIM- Write a program to create a binary file with roll number, name
and marks, input a roll number and update the marks.
SOFTWARE USED- IDLE (PYTHON 3.10 64-bit)
INPUT
#TO CREATE A BINARY FILE WITH ROLL NUMBER, NAME & MARKS, INPUT A ROLL NUMBER &
UPDATE THE MARKS.
import pickle
sdata={}
totals=int (input("Enter number of students :"))
a=open (r"C:\Users\Dell\Documents\ankitverma\Python\TEXT3.dat", "wb")
for i in range (totals):
sdata["Roll no"]=int (input ("Enter roll no. :))
sdata["Name"]=input("Enter name :")
sdata["Marks"]=float(input ("Enter marks :"))
pickle. dump (sdata, a)
sdata={}
a.close()
#UPDATING MARKS
found=False
rollno=int (input ("Enter roll number :"))
a=open (r"C:\Users\Dell\Documents\ankitverma\Python\TEXT3.dat", "rb+")
try:
while True:
pos=a. tell()
sdata=pickle.load(a)
if (sdata("Roll no"]==rollno):
sdata("Marks"]=float (input("Enter new marks :"))
a. seek (pos)
pickle. dump (sdata, a)
found=true
except EOFError:
if found==False:
print("Roll number not found.")
else:
print("Students marks updated successfully.")
a.close()
OUTPUT
AIM- Write a program to create a CSV file with empid, name and
mobile no. and search empid, update the record and display the
records
SOFTWARE USED- IDLE (PYTHON 3.10 64-BIT)
INPUT
#Input Data
import csv
with open (employee. txt', 'a') as csv file:
my writer = csv. Writer (csv file, delimiter=',')
ans ='y'
while an. Lower () =='Y':
eno = int (input ("Enter Employee ID:"))
name= input ("Enter Employee Name:")
mobile no. =int (input ("Enter Employee Mobile No:"))
my writer. Write row ([e no, name, mobile no.])
answer=input ("Do You Want To Enter More Data? (y/n):")
answer='y'
#Search Empid And Display The Records
with open (employee. txt', 'r') as csv file:
my reader = csv. reader (csv file, delimiter=',')
answer='y'
while an. Lower () == 'y':
found=false
e = int (input ("Enter Employee ID to search :"))
for row in my reader:
if len (row) !=0:
if int (row [O]) ==e:
print ("Name:", row [1])
print ("Mobile no.: " row [2])
found=true
break
if not found:
print ("Employee ID not found.")
answer = input ("Do You Want To Search More? (y/n):")
answer ='y'
with open (‘employee. txt', 'a') as csv file:
x=csv. writer (csv file)
x. write row ([eno, name, mobile no.])
OUTPUT
INPUT
OUTPUT
DELETE to remove tuple(s) GROUP BY and find the min, max, sum, count and
average
INPUT
use studentdb;
Database changed
CREATING TABLE
desc student;
INSERTING VALUE
desc student;
UPDATING VALUE
add(
desc student;
desc student;
ORDER BY COMMAND
COUNT COMMAND
INPUT
OUTPUT
Python 3.8. 6rel (tags/v3.8. 6rcl: 08bd63d, Sep 7 2020, 23:10:23) [MSC v.1927 64 bit (AMD64)] on win32 Type
"help","copyright", "credits" or "license ()" for more information.
>>>>>>>>
== RESTART: C:/Users/Dell/Documents/deepak.py===
(9100727,‘Deepak’,datetime.date(1989,3,24),'F',916457.0,'Security','Mumbai',datetime.date (2011,1,20))
(9100906,'Shubham',datetime.date(1985,12,7),'M',843749.0,'Sales','Hyderabad',datetime.date(2007,6, 18))
(9200172,”Adhiraj”,datetime.date(1986,11,21),'M',1470420.0,'Security','Hyderabad',datetime.date(2008,5, 3))
(9200593, 'Ashish', datetime.date (1988, 6, 17), 'M', 1237820.0, 'Legal', 'Delhi', datetime.date (2010, 11, 24))
(9300866, 'Anjali', datetime.date (1986, 1, 13), 'P', 1937590.0, 'Finance', 'Mumbai', datetime date (2008, 9, 28))
(9700356, 'Kartik', datetime. date (1987, 9, 30), 'M', 2163510.0, 'Sales', 'Delhi', datetime.date (2009, 2, 12))
PRACTICAL- 19
INPUT
OUTPUT
PRACTICAL- 20
INPUT
OUTPUT
PRACTICAL- 21
INPUT
OUTPUT
PRACTICAL- 22
INPUT
OUTPUT