XII CS PRATICALS 1 To16 PDF
XII CS PRATICALS 1 To16 PDF
INDEX
SL. DATE TOPIC TEACHER
NO. SIGN
1. 26/07/2020 WAP 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
2. 27/07/2020 WAP 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.
3. 28/07/2020 WAP 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. 29/07/2020 WAP input n numbers in tuple and pass it to function to count how many
even and odd numbers are entered.
5. 30/07/2020 WAP to function with key and value, and update value at that key in
dictionary entered by user
6. 31/07/2020 WAP to pass a string to a function and count how many vowels present in
the string
7. 01/08/2020 WAP to generator that generates random numbers between 1 and 6 using
user defined function
8. 02/08/2020 WAP to implement python mathematical functions.
10. 04/08/2020 WAP to make user define module and import same in another module or
program.
11. 05/08/2020 WAP to read and display file content line by line with each word separated
by #
12. 06/08/2020 WAP to remove all the lines that contain the character ‘a’ in a file and write
it to another file.
13. 07/08/2020 WAP 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”
14. 08/08/2020 WAP 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.
15 09/08/2020 WAP to create a binary file with roll number, name and marks, input a roll
number and update the marks.
16. 10/08/2020 WAP to create a CSV file with empid, name and mobile no. and search
empid, update the record and display the records.
17. 11/08/2020
18. 12/08/2020
3
19.
20.
21.
22.
23.
4
18. 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
19. Integrate SQL with Python by importing the MySQL module record of employee and display the
record.
20. 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.
21. Integrate SQL with Python by importing the MySQL module to search a student using rollno,
update the record.
22. Integrate SQL with Python by importing the MySQL module to search a student using rollno,
delete the record.
23. Take a sample of ten phishing e-mails (or any text file) and find most commonly occurring
word(s)
6
26/07/2020
AIM
WAP 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.7 32-bit)
#TO LINEAR SEARCH AN ELEMENT IN A LIST AND DISPLAY THE FREQUENCY AND LOCATION
def fun(l,x):
count=0
for i in range(0,len(l)):
if l[i]==x:
print("Found location =",i)
count+=1
print("Frequency of element",count)
a=eval(input("Enter a list ="))
b=eval(input("Element to be searched ="))
fun(a,b)
>>>
=======================RESTART:E:/SOFTWARE/ pritical1.py===================
Enter a list =[1,4,2,3,4,5,4,4]
Element to be searched =4
Found location = 1
Found location = 4
Found location = 6
Found location = 7
Frequency of element 4
7
27/07/2020
AIM
WAP 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.7 32-bit)
#TO BINARY SEARCH AN ELEMENT IN A LIST AND DISPLAY THE FREQUENCY AND LOCATION
def fun(l,a):
count=0
low=0
high=len(l)-1
while low<=high:
mid=int((low+high)/2)
if a==l[mid]:
count+=1
return ("Element found!,index:",mid,"Frequency:",count)
elif a<l[mid]:
high=mid-1
else:
low=mid+1
x=eval(input("Enter a list ="))
y=eval(input("Enter the element to search ="))
print(fun(x,y))>>>
========================RESTART:E:/SOFTWARE/pritical2.py ====================
Enter a list =[3,4,5,6,7]
Enter the element to search =7
('Element found!,index:', 4, 'Frequency:', 1)
8
28/07/2020
AIM
WAP 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.7 32-bit)
#TO PASS LIST & DOUBLE THE ODD VALUES AND HALF EVEN VALUES & DISPLAY THE CHANGED
LIST
def f(l):
l2=[]
for i in range(0,len(l)):
if l[i]%2==0:
e=l[i]/2
l2.append(e)
else:
e=l[i]*2
l2.append(e)
print(l2)
a=eval(input("Enter a list ="))
f(a)
>>>
======================== RESTART: E:/SOFTWARE/pratical3.py===================
29/07/2020
AIM
WAP 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.7 32-bit)
#TO INPUT N NUMBERS IN TUPLE & COUNT HOW MANY EVEN & ODD NUMBERS ARE ENTERED
def fun(l):
e=0
o=0
for i in range(0,len(l)):
if l[i]%2==0:
e+=1
else:
o+=1
print("Number of even numbers = ",e,"Number of odd numbers = ",o)
x=eval(input("Enter a tuple = "))
fun(x)
>>>
======================== RESTART: E:/SOFTWARE/pratical4.py===================
30/07/2020
AIM
WAP to function with key and value, and update value at that key in dictionary entered by user
SOFTWARE USED
IDLE (PYTHON 3.7 32-bit)
#TO UPDATE THE KEY AND VALUE OF EXISTING DICT ENTERED BY USER
def fun(d,k):
value2=eval(input("enter the value"))
d[k]=value2
print("updated dictionary:",d)
x=int(input("number of pairs in dictoinary:"))
dic={}
for i in range(x):
key=eval(input("enter the key"))
value=eval(input("enter the value"))
dic[key]=value
print("original dictionary:",dic)
a=(eval(input("enter the key whose value you wants to change")))
fun(dic,a)
>>>
======================== RESTART: E:/SOFTWARE/pratical5.py===================
Number of pairs in dictoinary = 3
Enter the key = "Name"
Enter the value = "Bhuvan Bam"
Enter the key = "Age"
Enter the value = 23
Enter the key = "Profession"
Enter the value = "Youtuber"
Original dictionary = {'Name': 'Bhuvan Bam', 'Age': 23, 'Profession': 'Youtuber'}
Enter the key whose value you wants to change = "Age"
Enter the value = 26
Updated dictionary = {'Name': 'Bhuvan Bam', 'Age': 26, 'Profession': 'Youtuber'}
11
31/07/2020
AIM
WAP to pass a string to a function and count how many vowels present in the string
SOFTWARE USED
IDLE (PYTHON 3.7 32-bit)
01/08/2020
AIM
WAP to generator that generates random numbers between 1 and 6 using user defined function
SOFTWARE USED
IDLE (PYTHON 3.7 32-bit)
#TO GENERATE RANDOM NUMBERS BETWEEN 1 AND 6 USING USER DEFINED FUNCTION
def fun():
import random
r=random.randint(1,6)
print("Random number generated between 1 to 6 = ",r)
fun()
>>>
======================== RESTART: E:/SOFTWARE/pratical7.py===================
Random number generated between 1 to 6 = = 3
>>>
======================== RESTART: E:/SOFTWARE/pratical7.py===================
Random number generated between 1 to 6 = = 1
>>>
======================== RESTART: E:/SOFTWARE/pratical7.py===================
Random number generated between 1 to 6 = = 4
>>>
======================== RESTART: E:/SOFTWARE/pratical7.py===================
Random number generated between 1 to 6 = = 2
13
02/08/2020
AIM
03/08/2020
AIM
>>>
======================== RESTART: E:/SOFTWARE/pratical9.py=====================
Enter sentence = LoWeR CaSe
enter the spacing = -
The string entered is a word = False
The string entered in lower case = lower case
The string entered is in lower case = False
The string entered in lower case = LOWER CASE
The string entered is in lower case = False
The string entered after removing the spave from left side = LoWeR CaSe
The string entered after removing the spave from right side = LoWeR CaSe
The string entered contains whitespace = False
The string entered is titlecased = False
The string entered after joining with - = L-o-W-e-R- -C-a-S-e
The string entered after swaping case = lOwEr cAsE
16
04/08/2020
AIM
WAP to make user define module and import same in another module or program
SOFTWARE USED
IDLE (PYTHON 3.7 32-bit)
#CALCULATOR MODULE
def add(a,b):
return a+b
def sub(a,b):
return a-b
def multi (a,b):
return a*b
def div (a,b):
return a/b
>>>
17
Enter a number = 6
Enter a number = 2
Addition of 6 and 2 = 8
Subtraction of 6 and 2 = 4
Multiplication of 6 and 2 = 12
Division of 6 and 2 = 3.0
__________________________________________________________________________
18
05/08/2020
AIM
WAP to read and display file content line by line with each word separated by #.
SOFTWARE USED
IDLE (PYTHON 3.7 32-bit)
#TO READ AND DISPLAY FILE CONTENT LINE BY LINE WITH EACH WORD SEPARATED BY #
a= open ("E:\\SOFTWARE\\TEXT.txt","r")
lines=a.readlines()
for line in lines:
x=line.split()
for y in x:
print(y+" # " , end=" ")
print(" ")
>>>
======================= RESTART: E:/SOFTWARE/pratical11.py=====================
Hello # World #
Welcome # to # python #
Enjoy # programing #
19
06/08/2020
AIM
WAP to remove all the lines that contain the character ‘a’ in a file and write it to another file.
SOFTWARE USED
IDLE (PYTHON 3.7 32-bit)
#TO REMOVE ALL THE LINES THAT CONTAIN THE CHARACTER ‘A’ IN A FILE & WRITE IT TO
ANOTHER FILE
file=open("E:\\SOFTWARE\\TEXT1.txt","r")
lines=file.readlines()
file.close()
file=open("E:\\SOFTWARE\\TEXT1.txt","w")
file1=open("E:\\SOFTWARE\\MODTEXT1.txt","w")
for line in lines:
if 'a' in line :
file1.write(line)
else:
file.write(line)
print("Lines that contain a character is removed from TEXT1")
print("Lines that contain a character is added in MODTEXT1 ")
file.close()
file1.close()
>>>
======================= RESTART: E:/SOFTWARE/pratical12.py=====================
20
07/08/2020
AIM
WAP 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
08/08/2020
AIM
WAP 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.
SOFTWARE USED
IDLE (PYTHON 3.7 32-bit)
23
09/08/2020
AIM
WAP to create a binary file with roll number, name and marks, input a roll number and update the
marks.
SOFTWARE USED
IDLE (PYTHON 3.7 32-bit)
__________________________________________________________________________
24
10/08/2020
AIM
WAP 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.7 32-bit)
25
11/08/2020
AIM
SOFTWARE USED
IDLE (PYTHON 3.7 32-bit)
26
12/08/2020
AIM
WAP
SOFTWARE USED
IDLE (PYTHON 3.7 32-bit)