Www Scribd
Www Scribd
Class-12-Computer
Science Practical File
2023-24
Uploaded by kalpanapradhan1179
Document Information
The document provides a practical file for a student'…
Download now
Download as pdf or txt
AISSCE-2023-24
PRACTICAL FILE
Student Name :
Grade :
Roll No. :
SUBMITTED TO
PRAFULLA KUMAR GOUDA
PGT COMPUTER SCIENCE)
Certificate
You're Reading a Preview
Upload your documents to download.
Principal
Page 2 of 45
14
percentage.
Upload to Download
Write a program to create a library in python
and import it in a program.
15 Take a sample of ten phishing e-mails (or any
OR
text file) and find the most commonly
occurring word(s).
16 Write a python program to implement a stack
Become
usingaa Scribd member to read and download full
list data-structure.
17 Write a program to implement a queue using
a list data structure.
documents.
18 SQL Queries
19 Startto your
Write a program connect30 daywith
Python free trial
MySQL using database connectivity and
perform the following operations on data in
database: Fetch, Update and delete the data.
Page 4 of 45
Practical No-1
SOURCE CODE:
You're Reading a Preview
num=int(input("Enter a number : "))
res=rem+res*10
num=num//10 OR
if res==n:
Become a Scribd
print("Number member to read and download full
is Palindrome")
else:
documents.
print("Number is not Palindrome")
Output -
Page 5 of 45
Practical No-2
var=True
You're Reading a Preview
while var:
Upload your documents
choice=int(input("Press-1 to find the ordinalto download.
value of a character \nPress-2
print(ord(ch))
elif choice==2: OR
val=int(input("Enter an integer value: "))
else:
documents.
print("You entered wrong choice")
Start
print("Do you want your 30
to continue? day
Y/N") free trial
option=input()
if option=='y' or option=='Y':
var=True
else:
var=False
Output -
Page 6 of 45
Enter a character : a
97
You're Reading a Preview
Do you want to continue? Y/N
Press-2 to findUpload
a characterto
of Download
a value
A OR
Do you want to continue? Y/N
Page 7 of 45
Practical No-3
Become a Scribd
print("Select member to read and download full
operation.")
print("1.Add")
documents.
print("2.Subtract")
Start
print("3.Multiply") your 30 day free trial
print("4.Divide")
while True:
if choice == '1':
Page 8 of 45
if next_calculation == "no":
else:
documents.
print("Invalid Input")
Page 9 of 45
Practical No-4
print(x)
print(y) OR
display()
Page 10 of 45
Practical No-5
consonants = 0
Upload to Download
spaces = 0
symbols = 0
str = str.lower() OR
for i in range(0, len(str)):
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);
Volwels: 3
White spaces: 3
Symbols: 3
OR
Page 12 of 45
Practical No-6
Upload
sub4=int(input("Enter marks to Download
of the fourth subject: "))
average=(sub1+sub2+sub3+sub4+sub5)/5
print("Average is ",average) OR
percentage=(average/total)*100
Become a Scribd
print("According member
to the percentage, ") to read and download full
if percentage >= 90:
documents.
print("Grade: A")
print("Grade: C")
print("Grade: D")
else:
print("Grade: E")
Page 13 of 45
Output -
Average is 7.6
Page 14 of 45
Practical No-7
import random
You're Reading a Preview
randomlist = []
Upload
for i in range(0,5): your documents to download.
n = random.randint(1,30)
Output - OR
Become
[10, a Scribd
5, 21, 1, 17] member to read and download full
documents.
Page 15 of 45
Practical No-8
# Write a program to read a text file line by line and display each word
separated by '#'.
You're Reading a Preview
filein = open("Mydoc.txt",'r')
for line in filein:
Upload your documents to download.
word= line .split()
for w in word:
print(w + '#',end ='')Upload to Download
print()
filein.close()
OR
OR
fin=open("D:\\python programs\\Book.txt",'r')
Become a Scribd
L1=fin.readlines( ) member to read and download full
s=' '
documents.
for i in range(len(L1)):
L=L1[i].split( )
Start your 30 day free trial
for j in L:
s=s+j
s=s+'#'
print(s)
fin.close( )
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.
You're Reading a Preview
filein = open("Mydoc1.txt",'r')
Upload
line = filein.read() your documents to download.
count_vow = 0
count_con = 0
Upload to Download
count_low = 0
count_up = 0
count_digit = 0 OR
count_other = 0
print(line)
Become a Scribd member to read and download full
for ch in line:
documents.
if ch.isupper():
count_up +=1
Start your 30 day free trial
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)
You're Reading a Preview
print("Consonants: ",count_con-count_vow)
filein.close()
OR
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")
You're Reading a Preview
Upload your documents
f2 = open("copyMydoc.txt","w") to download.
for line in f1:
f1.close() OR
f2.close()
f2 = open("copyMydoc.txt","r")
Become a Scribd member to read and download full
print(f2.read())
documents.
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
You're Reading a Preview
lines = 0 Upload your documents to download.
words = 0
letters = 0
Upload to Download
filesize = 0
lines += 1 OR
letters += len(line)
pos = 'out'
Start your 30 day free trial
for letter in line:
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
You're Reading a Preview
Upload your documents to download.
def Writerecord(sroll,sname):
pickle.dump(srecord,Myfile)
OR
def Readrecord():
print()
Start your 30 day free trial
while True:
try:
rec=pickle.load(Myfile)
except EOFError:
break
def Input():
Writerecord(sroll,sname)
if rec['SROLL']==roll:
OR
print("Roll NO:",rec['SROLL'])
print("Name:",rec['SNAME'])
def main():
while True:
print('1.Insert Records')
print('2.Dispaly Records')
Page 22 of 45
if ch==1:
You're Reading a Preview
Input()
Upload
elif ch==2: your documents to download.
Readrecord()
SearchRecord(r)
else: OR
break
Become a Scribd
main() member to read and download full
documents.
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.
You're Reading a Preview
Input a roll number and update details.
def Writerecord(sroll,sname,sperc,sremark):
Upload your documents to download.
with open ('StudentRecord.dat','ab') as Myfile:
srecord={"SROLL":sroll,"SNAME":sname,"SPERC":sperc,
Upload to Download
"SREMARKS":sremark}
pickle.dump(srecord,Myfile)
def Readrecord():
OR
with open ('StudentRecord.dat','rb') as Myfile:
while True:
try:
Start your 30 day free trial
rec=pickle.load(Myfile)
print(rec['SPERC'],'\t ',rec['SREMARKS'])
except EOFError:
break
def Input():
Writerecord(sroll,sname,sperc,sremark)
Upload
def Modify(roll): your documents to download.
with open ('StudentRecord.dat','rb') as Myfile:
try:
rec=pickle.load(Myfile) OR
newRecord.append(rec)
break
documents.
found=1
newRecord[i]['SNAME']=name
newRecord[i]['SPERC']=perc
newRecord[i]['SREMARKS']=remark
found =1
else:
Page 25 of 45
found=0
if found==0:
print('1.Insert Records') OR
print('2.Dispaly Records')
Become a Scribd
print('3.Update member to read and download full
Records')
documents.
print('0.Exit (Enter 0 to exit)')
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
You're Reading a Preview
Upload your documentsasto
with open('Student_Details.csv','w',newline='') download.
csvf:
writecsv=csv.writer(csvf,delimiter=',')
choice='y'
Upload to Download
while choice.lower()=='y':
readcsv=csv.reader(fileobject)
for i in readcsv:
print(i)
Page 27 of 45
Practical No-14
Upload to Download
#• Create modules Area.py and Calculator.py in Mypackage folder with
following code
# Area.py Module OR
import math
def rectangle(s1,s2):
Become a Scribd member to read and download full
area = s1*s2
documents.
return area
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):
You're Reading a Preview
s = n1 + n2
r = n1 - n2 Upload to Download
return r
def mult(n1,n2):
m = n1*n1 OR
return m
Become
def div(n1,n2):a Scribd member to read and download full
d=n1/n2
documents.
return d
def main():
area =Area.circle(r)
area = Area.rectangle(s1,s2)
Page 29 of 45
area = Area.triangle(s1,s2)
Become
print("\nTheaMultiplication
Scribd member to read and download full
is : ",Calculator.mult(num1,num2))
documents.
print("\nThe sub is : ",Calculator.sub(num1,num2))
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():
You're Reading a Preview
Upload
import collections your documents to download.
fin = open('email.txt','r')
a= fin.read()
Upload to Download
d={ }
L=a.lower().split()
for word in L: OR
word = word.replace(".","")
word = word.replace(",","")
Become a Scribd member to read and download full
word = word.replace(":","")
documents.
word = word.replace("\"","")
word = word.replace("!","")
Start your 30 day free trial
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()
You're Reading a Preview
#Driver CodeUpload your documents to download.
def main():
OR
Page 32 of 45
Practical No-16
def isempty(stk):
You're Reading a Preview
if stk==[]:
Upload
return True your documents to download.
else:
def push(stk,item):
stk.append(item) OR
top=len(stk)-1
Start
return "underflow" your 30 day free trial
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:
You're Reading a Preview
top=len(stk)-1
Upload
return stk[top] your documents to download.
print('stack is empty')
else: OR
top=len(stk)-1
for i in range(top-1,-1,-1):
documents.
print(stk[i])
def main():
stk=[]
top=None
while True:
print('''stack operation
1.push
2.pop
Page 34 of 45
3.peek
4.display
5.exit''')
You're Reading a Preview
choice=int (input('enter choice:'))
Practical No-17
return 0
OR
# Become a Scribd
Function to add elementsmember
in Queue to read and download full
def Enqueue(qLst,val):
documents.
qLst.append(val)
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
You're Reading a Preview
return val
Upload your documents to download.
# Function to Display top element of Queue
return "UnderFlow"
else: OR
front=0
documents.
# Function to Display elements of Queue
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()
You're Reading a Preview
Upload your documents to download.
# Driver function
front = rear = 0
while True: OR
print()
Become a Scribd
print("##### member#####")
QUEUE OPERATION to read and download full
print("1. ENQUEUE ")
documents.
print("2. DEQUEUE ")
Start
print("3. PEEK ") your 30 day free trial
print("4. DISPLAY ")
if choice == 1:
Enqueue(qList,ele)
elif choice == 2:
val = Dqueue(qList)
if val == "UnderFlow":
Page 38 of 45
print("Queue is Empty")
else:
Upload
elif choice==3: your documents to download.
val = Peek(qList)
Upload to
if val == "UnderFlow": Download
print("Queue is Empty")
else:
Display(qList)
documents.
elif choice==0:
main()
Page 39 of 45
Practical No-18
SQL
SOLUTION
Upload your documents to download.
Step-1 Create a database:
Upload to
Step-2 Display the databases Download
SHOW DATABASES;
Use Bank;
OR
Step-4: Create the table EMPLOYEE
Become
create a Scribd member
table Employee(Ecode int primaryto read and
key,Ename download
varchar(20) full
NOT NULL,
documents.
Dept varchar(15),City varchar(15), sex char(1), DOB date, Salary float(12,2));
Start
Insert data into the table your 30 day free trial
SOLUTION
10-23",23000.50);
SOLUTION
Page 40 of 45
SOLUTION
2. Display the name and department of those employees who work in surat
Become
SELECT Ename,aDept
Scribd
FROMmember to read
EMPLOYEE WHERE and download
city=’surat’ full
and salary > 25000;
documents.
3. Display the name of those female employees who work in Mumbai.
Solution:-
RND.
Solution:-
Solution:-
Page 41 of 45
B. Find the name and salary of those employees whose salary is between
35000 and 40000.
Upload to Download
SOLUTION
SELECT Ename, salary FROM EMPLOYEE WHERE salary BETWEEN 35000 and
40000;
OR
C. Find the name of those employees who live in guwahati, surat or jaipur city.
Become
SOLUTION a Scribd member to read and download full
documents.
SELECT Ename, city FROM EMPLOYEE WHERE city IN(‘Guwahati’,’Surat’,’Jaipur’);
D. Display the name of those employees whose name starts with ‘M’.
SOLUTION
SOLUTION
Page 42 of 45
SOLUTION
H.Find maximum salary of each department and display the name of that
OR in employee table.
a. Find the average salary of the employees
Solution:-
Solution:-
d. Find the total salary of those employees who work in Guwahati city.
Solution:-
Page 43 of 45
Practical No-19
import mysql.connector
Upload to Download
demodb = mysql.connector.connect(host="localhost", user="root",
passwd="computer", database="EDUCATION")
democursor=demodb.cursor( )
OR
democursor.execute("CREATE TABLE STUDENT (admn_no int primary key,
import mysql.connector
Start your 30 day free trial
demodb = mysql.connector.connect(host="localhost", user="root",
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( )
You're Reading a Preview
democursor.execute("select * from student")
Upload
for i in democursor: your documents to download.
print(i)
import mysql.connector
OR
demodb = mysql.connector.connect(host="localhost", user="root",
passwd="computer", database="EDUCATION")
demodb.commit( )
import mysql.connector
passwd="computer", database="EDUCATION")
democursor=demodb.cursor( )
demodb.commit()
Page 45 of 45
Cancel Anytime
Document 38 pages
Document 22 pages
Document 53 pages
Document 32 pages
Document 3 pages
Document 28 pages
Document 8 pages
20 Python Programs
uplifter40
100% (3)
Document 36 pages
School Management
Agrim Agarwal
100% (3)
Document 43 pages
Document 31 pages
Document 7 pages
Document 77 pages
Show more
About Suppor t
Privacy Policy
Third Parties
Storage
Documents
Targeted Advertising
Language: English
Personalization
Copyright © 2024 Scribd Inc.
Analytics
Manage Preferences
Accept All
Reject All