0% found this document useful (0 votes)
9 views26 pages

Practical File Content CS IJ

This document is a practical file for Computer Science (083) for the academic session 2025-2026, acknowledging the support of a teacher and detailing various Python programs and MySQL queries. It includes a total of 19 Python programs and 15 MySQL queries, covering topics such as data structures, file handling, and database operations. The document serves as a comprehensive guide for students to complete their practical assignments.

Uploaded by

Arindam Negi
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)
9 views26 pages

Practical File Content CS IJ

This document is a practical file for Computer Science (083) for the academic session 2025-2026, acknowledging the support of a teacher and detailing various Python programs and MySQL queries. It includes a total of 19 Python programs and 15 MySQL queries, covering topics such as data structures, file handling, and database operations. The document serves as a comprehensive guide for students to complete their practical assignments.

Uploaded by

Arindam Negi
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

PRACTICAL FILE

COMPUTER SCIENCE(083)

SESSION 2025-2026
ACKNOWLEDGEMENT

I, ________________________, student of class XII I/J express my


gratitude towards my teacher : MR. GURMEET SINGH ANAND
(P.G.T. , Computer Science/IP) for being kind in helping me to complete
this practical file for the session 2025-2026 for AISSCE (CBSE Board
Examination.)

This practical file consists of ( 15 +4 )=19 Programs using PYTHON/ ( with


MySql Interface) and (8 +7)= 15 Queries based on 2 tables, using MYSQL.

Thanking You

Name:________________________

Class/Section:__________________

Roll No:_______________________(Boards)
CERTIFICATE

This is to certify that ___________________________, is a student of


Class XII I/J of Doon International School. He/She has completed his/ her
Practical File as required, according to the pattern prescribed by CBSE for
the academic session 2025-2026. The work done is satisfactory and upto
my expectations.

Mr. Gurmeet [Link]


PGT [CS / IP]
DIS
PROGRAM 1

Q1 Write a program to create a list having numbers and then swap the first half with the
second half.

L=[]

L=eval(input(“Enter Numbers For a List……”))

L1=len(L)

mid=L1//2

for i in range(0,mid):

L[i],L[i+mid]=L[mid+i],L[i]

print(“The List after swapping…….”,L)


Program 2

Write a program to create a list having 10 numbers. Find the sum of only the three digit
numbers.

L=[]

sum=0

for i in range(0,10):

n=int(input(“Enter A Number……”))

[Link](n)

if(n>=100 and n<=999):

sum=sum+n

print(“sum of three digits numbers is …….”,sum)


Program 3

Q 3 Write a program to create a dictionary to hold account number as keys and balance
amount as values. The dictionary should hold data for 5 people. The program should display
the account numbers of those whose balance amount has fallen below the minimum balance
[Minimum Balance is Rs.3000].

Bank={}

for I in range(1,6):

Acno=input(“Enter Account Number……..”)

Bal=int(input(“Enter Balance Amount….”))

Bank[Acno]=Bal

for acnt_no in Bank:

if(Bank[acnt_no]<=3000):

print(“Account Number……..”,acnt_no,” Balance Amount…….”,Bank[acnt_no])


PROGRAM 4

Create a module: [Link] with definition of calculating cube of a number

function : cude(side)......side is an argument


use this module in another program to complete the task of checking a number
as Armstrong no.

# module [Link]

def cube(side):

return side*side*side

#another program

import Aarush # module to calculate cube


num=int(input("Enter the number:"))
x=num
sum=0
while num>0:
r=num%10
sum=sum+[Link](r)
num=num//10
print("Sum is:",sum)
if x==sum:
print("No is an Armstrong number")
else:
print("Number is not an Armstrong")
PROGRAM 5

Write a program to show the impact of default parameter when function is called with
different arguments multiple times

def module1(m,n=5):
m=m//n
n=n+m
print(m,"#",n)
return m

f=100
g=10
f=module1(f,g)
print(f,"$",g)
f=module1(g)
print(f,"$",g)
f=module1(f)
print(f,"$",g)
PROGRAM 6

Write a function to pass a string as an argument and count the number of vowels and
consonants present in a string.

def convow(str):
vow=0
con=0
for i in str:
if i in 'AEIOUaeiou':
vow=vow+1
else:
con=con+1
print("Total vowel",vow)
print("Total consonant",con)
str1=input("Enter the String")
convow(str1)
PROGRAM 7

Write a program to enter a string and write all capital letters in a new text file “[Link]”.
Then print each character on the screen.

gs=open("[Link]","w")
s=input("enter string")
for i in s:
if [Link]():
[Link](i)
[Link]()
gs=open("[Link]","r")
s=[Link]()
for i in s:
print(i,end=" ")
[Link]()
PROGRAM 8

Write a program to enter Rollnumber, Name and Percent of 10 students the write all data in
file a binary file “[Link]” . if any student is getting percent > 65 then print his/her
information on the screen.

import pickle
gs=open("[Link]","wb")
for i in range(0,10):
rno = int(input("enter roll no"))
name=input("enter name")
percent=float(input("enter percent"))
x=str(rno)+","+name+","+str(percent)
[Link](x,gs)
[Link]()
gsr=open("[Link]","rb")
for i in range(0,10):
x=[Link](gsr)
st=[Link](',')
if ((float(st[2])>65)):
print(st)
[Link]()
PROGRAM 9

Write a program to read a file "[Link]" and count how many digits are there.

gs=open("[Link]","w")
s=input("enter a string")
[Link](s)
[Link]()
gs=open("[Link]","r")
count=0
for line in gs:
words = [Link]()
for i in words:
for x in i:
if [Link]():
count =count+1
print("total digits=",count)
PROGRAM 10

Write a program to insert/append a record in a binary file “[Link]”

import pickle
record=[]
while True:
roll_no=int(input("Enter student Roll No:"))
name=input("Enter the Student name:"))
marks=int(input("Enter the marks obtained:"))
data=[roll_no,name,marks]
[Link](data)
choice=input("Wish to enter more records (Y/N)?: ")
if [Link]()=='N':
break

f=open("[Link]","wb")
[Link](record,f)
print("Record Added")
[Link]()
PROGRAM 11

Write a program to update the name of the student from the binary file

import pickle
f=open(“[Link]”,”rb”)
rec=[Link](f)
found=0
rollno=int(input(“Enter the roll number to search”))
for r in rec:
rno=r[0]
if rno==rollno:
print(“Current name is:”,r[1])
r[1]=input(“New Name:”)
found=1
break
if found==1:
[Link](0)
[Link](rec,f)
print( Name Updated!!!”)
[Link]()
PROGRAM 12

Write a program to create a csv file and write data about student
(Name’,’Class’,’Year’,’Percentage’) in it.

import csv
fields=[ 'Name','Class','Year','Percentage']
rows=[['Rohit','XII','2003','92'],
['Shaurya','XI','2004','82'],
['Deep','XII','2002','80'],
['Prerna','XI','2006','85'],
['Lakshya','XII','2005','72']]
filename='[Link]'
with open(filename,"w") as f:
csv_w=[Link](f,delimiter=',')
csv_w.writerow(fields)
for i in rows:
csv_w.writerows(i)
print("File created")
PROGRAM 13

Write a function push(arr) where arr is a list of [Link] all numbers which are divisible
by 5 in stack

def push(arr):
stack=[]
for x in range(0,len(arr)):
if arr[x]%5==0:
[Link](arr[x])
if stack==[]:
print("Stack empty")
else:
print(stack)

#main program

L=[20,21,24,25,32,36,45,56,60,43]
push(L)
PROGRAM 14

Write a menu driven program to implement a Stack for book details (book no, book name) as per
choice enter by a user.
[Link]
2. Display
3. Exit
def isEmpty(stk):
if stk==[]:
return True
else:
return False

def Push(stk,item):
[Link](item)
top=len(stk)-1

def Display(stk):
if isEmpty(stk):
print ("Stack Empty")
else:
top=len(stk)-1
print(stk[top],"top")
for a in range(top-1,-1,-1):
print(stk[a])

stack=[]
top=None
while (True):
print("Stack Operations:")
print ("1. PUSH")
print ("2. Display Stack")
print ("3. Exit")
ch=int(input("Enter your choice: "))
if (ch==1):
bno=input("Enter the book number to be inserted :")
bname=input("Enter the book name:")
item=[bno,bname]
Push(stack,item)
input()
elif (ch==2):
Display(stack)
input()
elif (ch==3):
break
else:
print("Invalid Choice")
input()
PROGRAM 15
Write a program to insert a new record into table student using Python interface and count the rows
inserted.

import [Link]
mydb = [Link](host="localhost",\
user="root",\
password="1234",\
database="DIS")
mycursor = [Link]()
[Link]("INSERT INTO student VALUES(2025,'Dinkar Gupta',12,'B',16,'M','Science')")
print([Link]," Rows inserted")

[Link]()
PROGRAM 16

Write a program to execute SELECT statement using Python interface and make use of fetchall()

import [Link]
con=[Link](host='localhost',user='root',password='1234',db='DIS')
stmt=[Link]()
query='select * from student;'
[Link](query)
data=[Link]()
print(data)

data1=[Link]()
for x in data1:
print (x)
PROGRAM 17

Write a program to delete records from a table and count how many rows are deleted; using Python
interface.

import [Link]
mydb = [Link](host="localhost",\
user="root",\
passwd="1234",\
database="DIS")
mycursor = [Link]()
[Link]("DELETE FROM student where Schlno=2025;" )
[Link]()
print([Link],"Record (s) Deleted")
Program 18
Write a code to generate an exception “ Something went wrong with opening the file” when file is
required to open in write mode.

try:
gs=open("[Link]")
try:
[Link]("Learning exception handling")
except:
print("Something went wrong when writing to the file")
finally:
[Link]()
except:
print("Something went wrong when opening the file")
Program 19

Write a code to generate an exception ‘ZeroDivisionError” when numerator is entered as zero


Solution:

print ("Handling multiple exceptions")


try:
numerator=50
denom=int(input("Enter the denominator: "))
print (numerator/denom)
print ("Division performed successfully")
except ZeroDivisionError:
print ("Denominator as ZERO is not allowed")
except ValueError:
print ("Only INTEGERS should be entered")
SQL
QUESTION-1

Consider the table SALES as given below:

I. To display the total quantity sold for each product whose total quantity sold exceeds 12.
II. To display the records of SALES table sorted by Product name in descending order.
III. To display the distinct Product names from the SALES table.
IV. To display the records of customers whose names end with the letter 'e'.
V. SELECT * FROM Sales where product='Tablet';
VI. SELECT sales_id, customer_name FROM Sales WHERE product LIKE 'S%';
VII SELECT COUNT(*) FROM Sales WHERE product in ('Laptop', 'Tablet');
VIII. SELECT AVG(price) FROM Sales where product='Tablet';

Answers

I. SELECT Product, SUM(Quantity_Sold) FROM SALES GROUP BY Product HAVING


SUM(Quantity_sold) > 12;
II. SELECT * FROM SALES ORDER BY Product DESC;
III. SELECT DISTINCT Product FROM SALES;
IV. SELECT * from SALES where Customer_Name like "%e";
V.

VI.
VII.

VIII

QUESTION-2

Given are the two tables: HOTELS, BOOKINGS. Write Queries to….

I. To display a list of customer names who have bookings in any hotel of 'Delhi' city.
II. To display the booking details for customers who have booked hotels in 'Mumbai',
'Chennai', or 'Kolkata'.
III. To delete all bookings where the check-in date is before 2024-12-03.
IV. A. To display the Cartesian Product of the two tables.
V. To display the customer’s name along with their booked hotel’s name.
VI. To change the field: Customer_Name to CName from a table: BOOKINGS
VII. To display all hotels ending ‘ai’ or ‘i’.

Answers

I. SELECT Customer_Name FROM Hotels, Bookings WHERE Hotels.H_ID = Bookings.H_ID


AND City = 'Delhi';
II. SELECT Bookings.* FROM Hotels, Bookings WHERE Hotels.H_ID = Bookings.H_ID AND
City IN ('Mumbai', 'Chennai', 'Kolkata');
III. DELETE FROM Bookings WHERE Check_In < '2024-12-03';
IV. A. SELECT * FROM Hotels, Bookings;
V. SELECT Customer_Name, Hotel_Name FROM Hotels, Bookings WHERE Hotels.H_ID =
Bookings.H_ID;
VI. Alter table Bookings CHANGE Customer_Name CName varchar(20);
VII. Select hotel_Name from Hotels were hotel_name like “%ai” or hotel_name like “%i”;

You might also like