0% found this document useful (0 votes)
387 views39 pages

Xii CS Practical Programs 2023 - 2024

This document contains instructions for 12 programming assignments on various Python topics for a Computer Science course. The assignments include: 1. Writing functions to perform linear and binary search on a list to find the frequency and location of an element. 2. Writing functions to modify lists by doubling odd values, halving even values, and counting even and odd numbers in tuples. 3. Writing functions to update dictionary values, count vowels in strings, and generate random numbers. 4. Implementing queue data structure using lists. 5. Implementing string and file handling functions to read/write/modify file contents. The assignments are to be completed in Python and include sample inputs, outputs and source

Uploaded by

harish balaji
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
387 views39 pages

Xii CS Practical Programs 2023 - 2024

This document contains instructions for 12 programming assignments on various Python topics for a Computer Science course. The assignments include: 1. Writing functions to perform linear and binary search on a list to find the frequency and location of an element. 2. Writing functions to modify lists by doubling odd values, halving even values, and counting even and odd numbers in tuples. 3. Writing functions to update dictionary values, count vowels in strings, and generate random numbers. 4. Implementing queue data structure using lists. 5. Implementing string and file handling functions to read/write/modify file contents. The assignments are to be completed in Python and include sample inputs, outputs and source

Uploaded by

harish balaji
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 39

SRI NACHAMMAL VIDYAVANI SR SEC SCHOOL

XII COMPUTER SCIENCE WITH PYTHON


TERM 1

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.

7. Write a Python program to generator(Random Number) that generates random


numbers between 1 and 6 (simulates a dice) using user defined function.

8. Write a python program to implement python mathematical functions.

9. Write a python program to implement python string functions.

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”
2
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.

TERM2
16. (i)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.(ii)stack using flight details(iii)stack using bank 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(ii) bank table (iii) flight table(iv) hospital table

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)

3
PRACTICAL- 1

AIM- Write a program to search an element in a list and


display the frequency of element present in list and
their location using Linear search
SOFTWARE USED - IDLE (PYTHON 3.8 64-bit)

INPUT

OUTPUT

4
PRACTICAL- 2

AIM- Write a to search an element in a list and display the


frequency of element present in list and their location
using Binary Search
SOFTWARE USED- IDLE (PYTHON 3.8 64-bit)

INPUT

OUTPUT

5
PRACTICAL- 3

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.8 64-bit)

INPUT

OUTPUT

6
7
PRACTICAL- 4

AIM- Write a program to input n numbers in tuple and pass it to


function to count how many even and odd numbers are entered
SOFTWARE USED- IDLE (PYTHON 3.8 64-bit)

INPUT

OUTPUT

8
9
PRACTICAL- 5

AIM- Write a program to function with key and value, and update value
at that key in dictionary entered by user

SOFTWARE USED- IDLE (PYTHON 3.8 64-BIT)

INPUT

OUTPUT

10
PRACTICAL- 6

AIM- Write a program to pass a string to a function and


count how many vowels present in the string
SOFTWARE USED- IDLE (PYTHON 3.8 64-BIT)

INPUT

OUTPUT

11
12
PRACTICAL- 7

AIM- Write a program to generator that generates random numbers


between 1 and 6 using user defined function
SOFTWARE USED- IDLE (PYTHON 3.8 64-BIT)

INPUT

OUTPUT(S)

13
14
PRACTICAL- 8

AIM- Program to implement Queue in Python using List.


SOFTWARE USED- IDLE (PYTHON 3.8 64-BIT)
def isEmpty(Q):
if len(Q)==0:
return True
else:
return False

def Enqueue(Q,item):
Q.append(item)
if len(Q)==1:
front=rear=0
else:
rear=len(
def Dequeue(Q):
if isEmpty(Q):
return "Underflow"
else:
val = Q.pop(0)
if len(Q)==0:
front=rear=None
return val
def Peek(Q):
if isEmpty(Q):
return "Underflow"
else:
front=0
return Q[front]
def Show(Q):
if isEmpty(Q):
print("Sorry No items in Queue ")
else:
t = len(Q)-1
print("(Front)",end
=' ') front = 0
i=front
rear = len(Q)-1
while(i<=rear):
print(Q[i],"==>",end=' ')
i+=1
print()
Q=[ ] #Queue
front=rear=None
while True:
15
print("**** QUEUE DEMONSTRATION ******")
print("1. ENQUEUE ")

print("2. DEQUEUE")
print("3. PEEK")
print("4. SHOW QUEUE ")
print("0. EXIT")
ch = int(input("Enter your choice :"))
if ch==1:
val = int(input("Enter Item to Insert :"))
Enqueue(Q,val)
elif ch==2:
val = Dequeue(Q)
if val=="Underflow":
print("Queue is Empty")
else:
print("\nDeleted Item was :",val)
elif ch==3:
val = Peek(Q)
if val=="Underflow":
print("Queue Empty")
else:
print("Front Item :",val)
elif ch==4:
Show(Q)
elif ch==0:
print("Bye")
break

OUTPUT

**** QUEUE DEMONSTRATION ******


0. ENQUEUE
1. DEQUEUE
2. PEEK
3. SHOW QUEUE
0. EXIT
Enter your choice :1 Enter
Item to Insert :10
**** QUEUE DEMONSTRATION ******
1. ENQUEUE
2. DEQUEUE
3. PEEK
4. SHOW QUEUE
0. EXIT
Enter your choice :1

16
Enter Item to Insert :20
**** QUEUE DEMONSTRATION ******
1. ENQUEUE
2. DEQUEUE
3. PEEK
4. SHOW QUEUE
0. EXIT
Enter your choice :1
Enter Item to Insert :30
**** QUEUE DEMONSTRATION ******
1. ENQUEUE
2. DEQUEUE
3. PEEK
4. SHOW QUEUE
0. EXIT
Enter your choice :4
(Front) 10 ==> 20 ==> 30 ==>
**** QUEUE DEMONSTRATION ******
1. ENQUEUE
2. DEQUEUE
3. PEEK
4. SHOW QUEUE
0. EXIT
Enter your choice :3
Front Item : 10
**** QUEUE DEMONSTRATION ******
1. ENQUEUE
2. DEQUEUE
3. PEEK
4. SHOW QUEUE
0. EXIT
Enter your choice :2
Deleted Item was : 10
**** QUEUE DEMONSTRATION ******
1. ENQUEUE
2. DEQUEUE
3. PEEK
4. SHOW QUEUE
0. EXIT
Enter your
choice :4 (Front)
20 ==> 30 ==>

**** QUEUE DEMONSTRATION ******


17
1. ENQUEUE
2. DEQUEUE
3. PEEK
4. SHOW QUEUE
0. EXIT
Enter your choice :0
Bye

18
PRACTICAL- 9

AIM- Write a program to implement python string functions


SOFTWARE USED- IDLE (PYTHON 3.8 64-BIT)

INPUT

OUTPUT

19
PRACTICAL- 10

AIM- Write a program to read and display file content line by line
with each word separated by #.
SOFTWARE USED- IDLE (PYTHON 3.8 64-BIT)

INPUT

OUTPUT

20
PRACTICAL- 11

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.8 64-BIT)

INPUT

OUTPUT

21
PRACTICAL- 12

AIM- Write a 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”
SOFTWARE USED- IDLE (PYTHON 3.8 64-bit)

INPUT

CRL\

OUTPUT

22
PRACTICAL- 13

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

SOFTWARE USED- IDLE (PYTHON 3.8 64-BIT)

INPUT

OUTPUT

23
PRACTICAL- 14

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.8 64-bit)

INPUT

OUTPUT

24
PRACTICAL- 15

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.8 64-BIT)

INPUT

25
OUTPUT

26
PRACTICAL- 16

AIM- Write a 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
SOFTWARE USED- IDLE (PYTHON 3.8 64-BIT)

INPUT

27
OUTPUT

28
PRACTICAL- 17

AIM- Write a program to 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

SOFTWARE USED- MySQL Workbench 8.0 CE

INPUT

use studentdb;

Database changed

CREATING TABLE

create table student

(roll int not null,

studentname varchar(30) not null,

class char(5) not null,

section char(1) not null,

classstream char(20) not null);

desc student;

INSERTING VALUE

insert into student values

(1, "Akhil", "XII", "A", "Science"),

(2, "Satya", "XII", "C", "Science"),

(3, "Antony", "XII", "D", "Commerce"),

(4, "Vishal", "XII", "E", "Humanities"),

(5, "Deepak", "XII", "A", "Science"),


29
(6, "Brij", "XII", "B", "Science");

select * from student;

ADDING COLUMN IN TABLE USING ALTER COMMAND

alter table student

add(Substream char(20) not null),

(Percentage float not null);

desc student;

UPDATING VALUE

update student set Substream = "Computer Science" where roll = 1;

update student set Substream = "Biology" where roll = 2;

update student set Substream = "Maths" where roll = 3;

update student set Substream = "NA" where roll = 4;

update student set Substream = "Computer Science" where roll = 5;

update student set Substream = "Computer Science" where roll = 6;

select * from student;

update student set Percentage = 81 where roll = 6;

update student set Percentage = 69 where roll = 6;

update student set Percentage = 92 where roll = 6;

30
update student set Percentage = 55 where roll = 6;

update student set Percentage = 85 where roll = 6;

update student set Percentage = 72 where roll = 6;

select * from student;

alter table student add(Adhaar_card bigint not null);

desc student;

alter table student

drop column Adhaar_card;

desc student;

ORDER BY COMMAND

select studentname,section from student order by Percentage;

31
AVERAGE COMMAND

select avg(Percentage) from student;

COUNT COMMAND

select count(*) from student;

MIN, MAX AND SUM COMMAND

select min(Percentage) from student;

select max(Percentage) from student;

select sum(Percentage)/count(*) from student where substream = "Computer Science";

DELETE A TUPLE FROM TABLE

delete from student where classstream = "Science";

select * from student;

32
PRACTICAL- 18

AIM- Write a program to Integrate SQL with Python by importing the


MySQL module record of employee and display the record.
SOFTWARE USED- IDLE (PYTHON 3.8 64-BIT)

MySQL Workbench 8.0 CE

INPUT

OUTPUT

33
34
PRACTICAL- 19

AIM- Write a program to 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.
SOFTWARE USED- IDLE (PYTHON 3.8 64-BIT)

MySQL Workbench 8.0 CE

INPUT

OUTPUT

35
36
PRACTICAL- 20

AIM- Write a program to Integrate SQL with Python by importing the


MySQL module to search a student using roll no, update the record
SOFTWARE USED- IDLE (PYTHON 3.8 64-BIT)

MySQL Workbench 8.0 CE

INPUT

OUTPUT

37
PRACTICAL- 21

AIM- Write a program to Integrate SQL with Python by importing the


MySQL module to search a student using roll no, delete the record.
SOFTWARE USED- IDLE (PYTHON 3.8 64-BIT)

MySQL Workbench 8.0 CE

INPUT

OUTPUT

38
39
PRACTICAL- 22

AIM- Write a program to Take a sample of ten phishing e-mails (or


any text file) and find most commonly occurring word(s)
SOFTWARE USED- IDLE (PYTHON 3.8 64-BIT)

INPUT

OUTPUT

40

You might also like