WWW Scribd
WWW Scribd
Class-12-Computer
Science Practical File
2023-24
Uploaded by kalpanapradhan1179
Document Information
Save
AISSCE-2023-24
PRACTICAL FILE
Student Name :
Grade :
Roll No. :
SUBMITTED TO
PRAFULLA KUMAR GOUDA
PGT COMPUTER SCIENCE)
Certificate
You're Reading a Preview
Become
This is to certify a Scribd member for full
that __________________________________________
access.
student of Class Your
XII Science firsthas
/ Commerce 30successfully
days are free.
completed their computer
Principal
Page 2 of 45
CLASS-XII
1 Write a program to check a number whether
You're Reading a Preview
Submission Teacher’s
Date Sign
it is palindrome or not.
Page 4 of 45
Practical No-1
SOURCE CODE:
while num>0:
Become a Scribd member for full
rem=num%10access. Your first 30 days are free.
res=rem+res*10
num=num//10
if res==n:
Continue Reading with Trial
print("Number is Palindrome")
else:
Output -
Page 5 of 45
Practical No-2
var=True
while var:
print(ord(ch))
elif choice==2:
Continue Reading with Trial
val=int(input("Enter an integer value: "))
print(chr(val))
else:
option=input()
if option=='y' or option=='Y':
var=True
else:
var=False
Output -
Page 6 of 45
Enter a character : a
97
A
Continue Reading with Trial
Do you want to continue? Y/N
Page 7 of 45
Practical No-3
return x / y
Continue Reading with Trial
print("Select operation.")
print("1.Add")
print("2.Subtract")
print("3.Multiply")
print("4.Divide")
while True:
if choice == '1':
Page 8 of 45
break
else:
print("Invalid Input")
Output -
Select operation.
1.Add
2.Subtract
3.Multiply
4.Divide
Enter choice(1/2/3/4): 3
Enter first number: 15
Enter second number: 14
15.0 * 14.0 = 210.0
Let's do next calculation? (yes/no): no
Page 9 of 45
Practical No-4
x = "global "
print(y)
display()
Continue Reading with Trial
Output -
global global
local
Page 10 of 45
Practical No-5
vowels = 0
You're Reading a Preview
digits = 0
str = str.lower()
Continue Reading with Trial
for i in range(0, len(str)):
vowels = vowels + 1
consonants = consonants + 1
digits = digits + 1
spaces = spaces + 1
else:
symbols = symbols + 1
print(“Vowels: “, vowels);
print(“Consonants: “, consonants);
print(“Digits: “, digits);
Page 11 of 45
print(“Symbols : “, symbols);
Output -
You're Reading a Preview
Enter the string : 123 hello world $%&45
Volwels: 3
Consontants: 7
Become a Scribd member for full
Digits: 5 access. Your first 30 days are free.
White spaces: 3
Symbols: 3
Continue Reading with Trial
Page 12 of 45
Practical No-6
average=(sub1+sub2+sub3+sub4+sub5)/5
print("Average is ",average)
Continue Reading with Trial
percentage=(average/total)*100
print("Grade: A")
print("Grade: B")
print("Grade: C")
print("Grade: D")
else:
print("Grade: E")
Page 13 of 45
Output -
Average is 7.6
Grade: C
Continue Reading with Trial
Page 14 of 45
Practical No-7
import random
randomlist = []
Output -
Continue Reading with Trial
[10, 5, 21, 1, 17]
Page 15 of 45
Practical No-8
# Write a program to read a text file line by line and display each word
separated by '#'.
filein = open("Mydoc.txt",'r')
for line in filein:
You're Reading a Preview
word= line .split()
Output -
Text in file:
hello how are you?
python is case-sensitive language.
Output in python shell:
hello#how#are#you?#python#is#case-sensitive#language.#
Page 16 of 45
Practical No-9
# Read a text file and display the number of vowels/ consonants/ uppercase/
lowercase characters and other than character and digit in the file.
filein = open("Mydoc1.txt",'r')
line = filein.read()
You're Reading a Preview
count_vow = 0
count_digit = 0
for ch in line:
if ch.isupper():
count_up +=1
if ch.islower():
count_low += 1
if ch in 'aeiouAEIOU':
count_vow += 1
if ch.isalpha():
count_con += 1
if ch.isdigit():
count_digit += 1
count_other += 1
Page 17 of 45
print("Digits",count_digit)
print("Vowels: ",count_vow)
print("Consonants: ",count_con-count_vow)
Page 18 of 45
Practical No-9
# Remove all the lines that contain the character `a' in a file and write it to
another file
f1 = open("Mydoc.txt")
f1.close()
print(f2.read())
Page 19 of 45
Practical No-10
# Write a Python code to find the size of the file in bytes, the number of lines,
number of words and no. of character.
import os
lines = 0
You're Reading a Preview
words = 0
lines += 1
filesize = os.path.getsize("Mydoc.txt")
pos = 'out'
words += 1
pos = 'in'
pos = 'out'
print("Lines:", lines)
print("Words:", words)
print("Letters:", letters)
Page 20 of 45
Practical No-11
# Create a binary file with the name and roll number. Search for a given roll
number and display the name, if not found display appropriate message.
import pickle
pickle.dump(srecord,Myfile)
print()
while True:
try:
rec=pickle.load(Myfile)
except EOFError:
break
def Input():
Writerecord(sroll,sname)
def SearchRecord(roll):
while True:
try:
Become a Scribd member for full
access. Your first 30 days are free.
rec=pickle.load(Myfile)
if rec['SROLL']==roll:
print("Roll NO:",rec['SROLL'])
Continue Reading with Trial
print("Name:",rec['SNAME'])
except EOFError:
print("Try Again..............")
break
def main():
while True:
print('1.Insert Records')
print('2.Dispaly Records')
Page 22 of 45
if ch==1:
Input()
elif ch==3:
Become a Scribd member for full
access. Your first 30 days are free.
r=int(input("Enter a Rollno to be Search: "))
SearchRecord(r)
else:
break
Continue Reading with Trial
main()
Page 23 of 45
Practical No-12
# Create a binary file with roll number, name and marks. Input a roll number
and update details. Create a binary file with roll number, name and marks.
Input a roll number and update details.
"SREMARKS":sremark}
access. Your first 30 days are free.
pickle.dump(srecord,Myfile)
def Readrecord():
print('Percetage',' ','Remarks')
while True:
try:
rec=pickle.load(Myfile)
print(rec['SPERC'],'\t ',rec['SREMARKS'])
except EOFError:
break
def Input():
Writerecord(sroll,sname,sperc,sremark)
rec=pickle.load(Myfile)
Continue Reading with Trial
newRecord.append(rec)
except EOFError:
break
found=1
for i in range(len(newRecord)):
if newRecord[i]['SROLL']==roll:
newRecord[i]['SNAME']=name
newRecord[i]['SPERC']=perc
newRecord[i]['SREMARKS']=remark
found =1
else:
Page 25 of 45
found=0
if found==0:
pickle.dump(j,Myfile)
print('1.Insert Records')
Continue Reading with Trial
print('2.Dispaly Records')
print('3.Update Records')
if ch==1:
Input()
elif ch==2:
Readrecord()
elif ch==3:
Modify(r)
else:
break
main()
Page 26 of 45
Practical No-13
# Write a program to perform read and write operation onto a student.csv file
having fields as roll number, name, stream and percentage.
import csv
writecsv=csv.writer(csvf,delimiter=',')
writecsv.writerow([rl,n,p,r])
readcsv=csv.reader(fileobject)
for i in readcsv:
print(i)
Page 27 of 45
Practical No-14
area = s1*s2
return area
def circle(r):
area= math.pi*r*r
return area
def square(s1):
area = s1*s1
return area
def triangle(s1,s2):
area=0.5*s1*s2
Page 28 of 45
return area
# Calculator.py Module
def sum(n1,n2):
s = n1 + n2
r = n1 - n2
Become a Scribd member for full
return r access. Your first 30 days are free.
def mult(n1,n2):
m = n1*n1
return m
Continue Reading with Trial
def div(n1,n2):
d=n1/n2
return d
# main() function
def main():
area =Area.circle(r)
area = Area.rectangle(s1,s2)
Page 29 of 45
area = Area.triangle(s1,s2)
main()
Page 30 of 45
Practical No-15
# Take a sample of ten phishing e-mails (or any text file) and find the most
commonly occurring word(s).
def Read_Email_File():
import collections
You're Reading a Preview
fin = open('email.txt','r')
for word in L:
Continue Reading with Trial
word = word.replace(".","")
word = word.replace(",","")
word = word.replace(":","")
word = word.replace("\"","")
word = word.replace("!","")
word = word.replace("&","")
word = word.replace("*","")
for k in L:
key=k
if key not in d:
count=L.count(key)
d[key]=count
word_counter = collections.Counter(d)
Page 31 of 45
fin.close()
Page 32 of 45
Practical No-16
def isempty(stk):
if stk==[]:
stk.append(item)
top=len(stk)-1
Continue Reading with Trial
def pop(stk):
if isempty(stk):
return "underflow"
else:
item=stk.pop()
if len(stk)==0:
top=None
else:
top=len(stk)-1
return item
def peek(stk):
Page 33 of 45
if isempty(stk):
return "underflow"
else:
top=len(stk)-1
print('stack is empty')
else:
top=len(stk)-1
Continue Reading with Trial
print(stk[top],'<-top')
for i in range(top-1,-1,-1):
print(stk[i])
#Driver Code
def main():
stk=[]
top=None
while True:
print('''stack operation
1.push
2.pop
Page 34 of 45
3.peek
4.display
5.exit''')
choice=int (input('enter choice:'))
if choice==1:
You're Reading a Preview
item=int(input('enter item:'))
Practical No-17
return Become
1 a Scribd member for full
else: access. Your first 30 days are free.
return 0
def Enqueue(qLst,val):
qLst.append(val)
if len(qLst)==1:
front=rear=0
else:
rear=len(qLst)-1
def Dqueue(qLst):
if isEmpty(qLst):
return "UnderFlow"
else:
Page 36 of 45
val = qLst.pop(0)
if len(qLst)==0:
front=rear=None
return val
def Peek(qLst):
Become a Scribd member for full
access. Your first 30 days are free.
if isEmpty(qLst):
return "UnderFlow"
else:
front=0
Continue Reading with Trial
return qLst[front]
def Display(qLst):
if isEmpty(qLst):
else:
tp = len(qLst)-1
print("[FRONT]",end=' ')
front = 0
i = front
rear = len(qLst)-1
while(i<=rear):
Page 37 of 45
print(qLst[i],'<-',end=' ')
i += 1
print()
def main():
Become a Scribd member for full
qList = [] access. Your first 30 days are free.
front = rear = 0
while True:
print()
Continue Reading with Trial
print("##### QUEUE OPERATION #####")
if choice == 1:
Enqueue(qList,ele)
elif choice == 2:
val = Dqueue(qList)
if val == "UnderFlow":
Page 38 of 45
print("Queue is Empty")
else:
val = Peek(qList)
Become a Scribd member for full
if val == "UnderFlow":
else:
Display(qList)
elif choice==0:
print("Good Luck......")
break
main()
Page 39 of 45
Practical No-18
SQL
Create a table EMPLOYEE with constraints
SOLUTION
You're Reading a Preview
Step-1 Create a database:
Use Bank;
Continue Reading with Trial
Step-4: Create the table EMPLOYEE
SOLUTION
10-23",23000.50);
SOLUTION
Page 40 of 45
SOLUTION
2. Display the name and department of those employees who work in surat
Solution:-
Continue Reading with Trial
SELECT Ename, Dept FROM EMPLOYEE WHERE city=’surat’ and salary > 25000;
Solution:-
RND.
Solution:-
Solution:-
Page 41 of 45
SOLUTION
You're Reading a Preview
SELECT DISTINCT(Dept) FROM EMPLOYEE;
SOLUTION
access. Your first 30 days are free.
SELECT Ename, salary FROM EMPLOYEE WHERE salary BETWEEN 35000 and
40000;
Continue Reading with Trial
C. Find the name of those employees who live in guwahati, surat or jaipur city.
SOLUTION
D. Display the name of those employees whose name starts with ‘M’.
SOLUTION
SOLUTION
SOLUTION
Page 42 of 45
SOLUTION
H.Find maximum salary of each department and display the name of that
SOLUTION
Become a Scribd member for full
SELECT Dept, max(salary) FROM EMPLOYEE group by Dept HAVING
max(salary)>39000;
access. Your first 30 days are free.
Queries for Aggregate functions- SUM( ), AVG( ), MIN( ), MAX( ), COUNT( )
Solution:-
Solution:-
d. Find the total salary of those employees who work in Guwahati city.
Solution:-
Page 43 of 45
Practical No-19
SOLUTION
democursor=demodb.cursor( )
float(4,2))")
SOLUTION
import mysql.connector
passwd="computer", database="EDUCATION")
democursor=demodb.cursor( )
democursor.execute("insert into student values (%s, %s, %s, %s, %s, %s)",
demodb.commit( )
SOLUTION
import mysql.connector
Page 44 of 45
passwd="computer", database="EDUCATION")
democursor=demodb.cursor( )
import mysql.connector
democursor=demodb.cursor( )
demodb.commit( )
SOLUTION
import mysql.connector
passwd="computer", database="EDUCATION")
democursor=demodb.cursor( )
demodb.commit()
Page 45 of 45
Cancel Anytime
Document 32 pages
Document 53 pages
Document 26 pages
Cs Investigatory
Sanjana Joshi
No ratings yet
Magazines Podcasts
Sheet music
Document 12 pages
1 Cs
Shubh Chandegara
No ratings yet
Document 36 pages
Comprehensive Python
Programming Solutions
Soumen Mahato
No ratings yet
Document 35 pages
Program to Create a
Binary File to Store…
Saksham Sharma
No ratings yet
Document 26 pages
Document 38 pages
Class 12 - Computer
Science Practical File…
Hriman Mittal
100% (1)
Document 24 pages
Grade 12 Physics
Practical Manual
santhoshsiva10092006
No ratings yet
Document 10 pages
Informatics Practices
Project File:: Name:…
Shambhavi Singh
No ratings yet
Document 9 pages
Python Programming:
Insights into Class XII…
Aditya Jyoti
No ratings yet
Document 3 pages
Test 1 - Jupyter
Notebook
दशानन रावण
No ratings yet
Show more
About Suppor t
Privacy Policy
Get our
Storage fr ee apps
Preferences
Third Parties
Storage
Targeted Advertising
Documents
Personalization
Language: English
Analytics
Save
Accept All