COMPUTER
COMPUTER
School
COMPUTER SCIENCE
PRACTICAL
FILE
Name – Ansh
Class – XII – A
Roll Ni
CERTIFICATE
1
This is to certify that Ansh Ajmani has completed
the Practical file. Through dedication, creativity,
and hard work,
has demonstrated exceptional skills and contributed
significantly to the success of the project .
Signature
___________
ACKNOWLEDGEMENT
2
I extend my heartfelt thanks to my Computer Science
mentor, Mrs Priyanka, for their invaluable guidance
unwavering support, and insightful feedback
throughout the project. Their expertise and
encouragement played a pivotal role in shaping the
practical file outcome. I am also thankful to my
teammates and colleagues who collaborated
seamlessly, bringing diverse skills and perspectives to
the practical file. Our collective efforts and teamwork
significantly enriched the project's overall quality.
I appreciate the cooperation and understanding of
all those who directly.
Sig
nature
INDEX
Sno. Title Signature
1 Calculating Cube
2 Checking similarity
3 Generating n digit random num
4 Generating equidistant series
5 Removing specific letter from str
6 Testing capword()
7 lengthconversion.py module creation
8 Fetching the number from txt file
9 Counting the numbers of lines in a text file
10 Updating data in a binary file
11 Creating add() and ccuntr ( ) function
12 Displaying words of specific length
13 Stack Implementation
14 Queue implementation
15 Creating table department
16 Creating table Employee
17 Changing name of column
18 Showing the structure of A Table
3
19 Joining two table
20 Adding a column In a table
21 Deleting a column in a Table
22 Using like to see specific records
23 Using more than to see specific record
24 Changing data of a specific record
25 Sorting records in a particular order
26 Finding minimum entry
27 Finding Maximum Entry
28 Finding the Avg
29 Dropping a table
OUTPUT:
(i) Enter the number for cube root: 2
4
Program-
1
Q1 Write a program to have the following functions:
1) A function that takes a number as an argument and calculates
a cube for it. The
function does not return value. If there is no value passed to the
function in
the function call the function should calculate a cube of 2.
2) a function that takes two char arguments and returns True if
both the
arguments are equal otherwise False.
Test both these functions by giving appropriate function call
statements
1) def cube( a = 2 ) :
print( "Cube of ", a ,"=" , a ** 3 )
num = input("Enter a number (For empty press Enter ) :")
if num == "" :
print(cube())
5
else :
print(cube( int (num) ))
2) def chr(char1,char2) :
if char1 == char2 :
return "True”
else :
return"False "
char1 = input("Enter a Char 1 : ")
char2 = input("Enter a Char 2 : ")
print(chr(char1,char2))
OUTPUT –
2
Enter number of digit: 23
77180670666340519158266
6
PROGRAM – 2
Q. Write a function that takes a number n and then returns a
randomly generated
number having exactly n digits (not starting with zero) eg. if n is
2 then function
can randomly return a number 10-99 but 07, 02 etc. are not valid
two digit
numbers.
import random
def ran(x) :
a= 10**(x-1)
b=10**(x)
print(random.randint(a,b-1))
n = int(input(“enter no. of digit :”))
7
ran(n)
OUTPUT –
3
Enter first Term = 1
Enter last Term = 7
Series = 1 3 5 7
8
PROGRAM – 3
Q Write a program that generates a series using a function which
takes first and
last values of the series and then generates four terms that are
equidistant e.g., if
two numbers passed are 1 and 7 then function returns 13 5 7.
def ser(a,b) :
d = int((b-a)/3)
9
print(“series =”,a,a+d,a+2*d,b)
first = int(input(“enter first term :”))
last=int(input(“enter last term :”))
ser(first,last)
OUTPUT –
4
(i) Enter a sentence = hello
Enter a letter = e
10
(ii) Enter a sentence = my name is ansh
Capital word = MY NAME IS ANSH
by upper method MY NAME IS ANSH
PROGRAM – 4
(i) def remove_letter( sentence , letter ) :
new_sentence = “”
sen = sentence.split ( letter )
11
for i in sen :
new_sentence += i
return new_sentence
sentence = input(“Enter a sentence = “)
letter = input(“Enter a letter = “)
print ( remove_letter (sentence , letter) )
new_sentence = “ “.join(sentan)
return new_sentence
OUTPUT –
5
12
PS C:\Users\Ansh\Desktop\CS holiday homework>
&
C:/Users/Ansh/AppData/Local/Programs/Python/P
ython311/python.exe “c:/Users/Ansh/Desktop/CS
holiday homework/code5.py”
8
9
8
9
8
9
8
9
8
9
8
9
13
Program –
5
F = open(“an.txt”, “r”)
for line in F :
words = line.split()
for i in words :
for letter in i :
if(letter. isdigit()) :
print(letter)
14
OUTPUT –
6
Total lines : 2
15
PROGRAM - 6
def COUNTLINES():
file=open(‘STORY.TXT’,’r’)
lines = file.readlines()
count=0
for w in lines:
if w[0]==”A” or w[0]==”a”:
count=count+1
print(“Total lines” , count)
file.close()
#_main_
COUNTLINES()
16
OUTPUT –
7
empl.dat
Empno : 1250 Salary : 11000
Empno : 1251 Salary : 12000
Empno : 1252 Salary : 5000
Record(s) successfully updated.
Empno : 1250 Salary : 11000
Empno : 1251 Salary : 14000
Emono : 1252 Salary : 5000
17
PROGRAM – 7
#For Output, At first we have to write something in the
emp.dat file by the #following code :-
import pickle
f = open(“empl.dat”,”wb”)
while True :
empno = int(input (“Enter Empno. ( for exit enter -
1 ):- “))
if empno == -1 :
print()
break
name = input( “Enter Name of Employee :-”)
sal = float(input(“Enter Salary of Employee :- “))
dic = { ‘Empno’ : empno , “Name” : name, ‘Salary’ :
sal }
pickle.dump( dic , f )
print()
print(“All Data are written Successfully “)
f.close()
#Then
import pickle
emp = {}
18
found = False
fin = open(‘empl.dat’, ‘rb+’)
fin.seek (0)
try:
while True :
rpos = fin.tell()
emp = pickle.load(fin)
if emp[‘Empno’] == 1251 :
emp[ ‘Salary’] = emp[‘Salary’] + 2000
fin.seek (rpos)
pickle.dump(emp, fin)
print (emp)
found = True
except EOFError:
if found == False:
print(“Sorry, no matching record found.”)]
else:
print(“Record(s) successfully updated.”)
fin.close()
19
OUTPUT –
8
Enter employee id: 1
Enter name: Ansh
Enter mobile number: 9671267565
Enter employee id: 2
Enter name: Good
Enter mobile number: 776786783
20
PROGRAM - 8
import csv
def ADD():
f = open(‘record.csv’, ‘a’, newline = “\n”)
write = csv.writer(f)
empid = int(input(“Enter employee id: “))
name = input(“Enter name: “)
mobile = int(input(“Enter mobile number: “))
list = [empid, name, mobile]
write.writerow(list)
f.close()
def COUNTER():
f = open(‘record.csv’, ‘r’ , newline= “\n”)
record = csv.reader(f)
print(“Number of record in the csv file: “, len(list(record)))
f.close()
ADD()
ADD()
COUNTER()
21
OUTPUT –
9
>> import lengthconversion as l
>>> l.miletokm( 1000 )
1609.344
>>> l.miletokm( 45628 )
73431.14803200001
>>> l.kmtomile( 1000 )
621.371192237334
>>> l.kmtomile( 74873 )
46523.925276385904
>>> l.feettoinches( 1000 )
83.33333333333333
>>> l.feettoinches( 35524 )
2960.3333333333335
>>> l.inchestofeet( 1000 )
12000
>>> l.inchestofeet( 24232 )
290784
>>> help( l )
Help on module lengthconversion:
NAME
lengthconversion
FUNCTIONS
feettoinches(x)
Return value in inches from feet
inchestofeet(x)
Return value in feet from inches
kmtomile(x)
Return value in miles from kilometer
miletokm(x)
Return value in kilometer from miles
DATA
22
one_feet_in_inche = 12
one_mille_in_km = 1.609344
FILE
c:\users\Ansh\desktop\holidayhomework\
lengthconversion.py
PROGRAM – 9
lengthconverstion.py
one_mille_in_km = 1.609344
one_feet_in_inche = 12
def miletokm(x) :
“Return value in kilometer from miles “
return x * one_mille_in_km
def kmtomile(x) :
“Return value in miles from kilometer “
return x / one_mille_in_km
def feettoinches( x ):
“Return value in inches from feet “
return x / one_feet_in_inche
def inchestofeet(x) :
“Return value in feet from inches “
return x * one_feet_in_inche
23
OUTPUT –
10
Word with length smaller than 3 :-
A
boy
is
is
a
An
is
in
the
&
are
in
is
24
Program -10
def DISPLAYWORDS() : STORY.TXT
file = open(“story.txt”, “r”) A boy is playing their.
lst = file.readlines() Their is a playground.
for i in lst : An aeroplaneis in the sky.
word = i.split()
for j in word :
if len( j ) < 4 :
print( j )
file.close()
print(“Word with length smaller than 3 :- \n”)
DISPLAYWORDS()
25
STACKS
AND
QUEUE
26
PROGRAM
S
PROGRAM – 11
S = []
def isEmpty(stk):
if stk == []:
return True
else:
return False
def push(stk, item):
stk.append(item)
top = len(stk) -1
def s_pop(stk):
if isEmpty(stk):
print('Underflow')
27
else:
top = len(stk)- 1
i = stk.pop()
if len(stk) == 0:
top = None
else:
top = top - 1
def peek(stk):
if isEmpty(stk):
return ("Underflow")
else:
top = len(stk) - 1
return stk[top]
def Display(stk):
OUTPUT –
11
Enter the Number from 1, 2, 3, 4, 5: 1
Enter the number in stack: 2
2 is added in the stack successfully
Enter the Number from 1, 2, 3, 4, 5: 1
Enter the number in stack: 3
3 is added in the stack successfully
Enter the Number from 1, 2, 3, 4, 5: 1
28
Enter the number in stack: 4
4 is added in the stack successfully
Enter the Number from 1, 2, 3, 4, 5: 4
4 <<< top
1
0
Enter the Number from 1, 2, 3, 4, 5: 2
top value is removed
Enter the Number from 1, 2, 3, 4, 5: 4
3 <<< top
0
Enter the Number from 1, 2, 3, 4, 5: 3
The topmost value of stack: 3
Enter the Number from 1, 2, 3, 4, 5: 5
if isEmpty(stk):
return None
else:
top = len(stk)- 1
s = stk[top]
print(s, "<<< top")
for i in range(top-1, -1, -1):
print(i)
while True:
i = int(input("Enter the Number from 1, 2, 3, 4, 5: "))
if i == 1:
29
h = int(input("Enter the number in stack: "))
push(S, h)
print(f"{h} is added in the stack successfully")
elif i == 2:
s_pop(S)
print("top value is removed")
elif i == 3:
print(f"The topmost value of stack: {peek(S)}")
elif i == 4:
Display(S)
elif i == 5:
break
else:
print("Write the correct value to work program")
OUTPUT –
12
Queue Implementation
1. Enqueue
2. Dequeue
3. Peek
4. Display
30
5. Exit
Enter the Value:1
Enter the value to enqueue in Queue: 2
Queue Implementation
1. Enqueue
2. Dequeue
3. Peek
4. Display
5. Exit
Enter the Value:1
Enter the value to enqueue in Queue: 4
Queue Implementation
1. Enqueue
2. Dequeue
3. Peek
4. Display
5. Exit
Enter the Value:1
PROGRAM – 12
# program for queue
q = []
r = None
f = None
def isEmpty(Q):
if Q == []:
return True
31
else:
return False
def dequeue(Q):
if isEmpty(Q):
return ("Under Flow")
else:
Q.pop(0)
if len(Q) == 0:
(OUTPUT )
Enter the value to enqueue in Queue: 5
Queue Implementation
1. Enqueue
2. Dequeue
3. Peek
4. Display
5. Exit
Enter the Value:4
2 <<<<--- Front
1
5 <<---- rear
32
Queue Implementation
1. Enqueue
2. Dequeue
3. Peek
4. Display
5. Exit
Enter the Value:2
None is dequeued Successfully
Queue Implementation
1. Enqueue
2. Dequeue
3. Peek
4. Display
5. Exit
Enter the Value:1
f= r =None
else:
f=0
def peek(Q):
if isEmpty(Q):
return ("Under flow")
else:
f= 0
return Q[0]
def display(Q):
if isEmpty(Q):
33
f = r= None
print("Under flow")
elif len(Q) == 1:
print(Q[0], "<<<< --- Front <<<<<< -- Rear")
else:
r = len(Q)-1
f=0
print(f"{Q[0]} <<<<--- Front")
for i in range(1, r):
print(i)
(OUTPUT)
34
Queue Implementation
1. Enqueue
2. Dequeue
3. Peek
4. Display
5. Exit
Enter the Value:3
4
Queue Implementation
1. Enqueue
2. Dequeue
3. Peek
4. Display
5. Exit
Enter the Value:5
while True:
print("Queue Implementation")
print("1. Enqueue")
print("2. Dequeue")
print("3. Peek")
print("4. Display")
print("5. Exit")
35
elif i == 2:
h = dequeue(q)
print(h, "is dequeued Successfully")
elif i == 3:
print(peek(q))
elif i == 4:
display(q)
elif i == 5:
break
else:
print("Pls input correctly")
print('\n\n\n')
36
SQL
QUERIES
37