You are on page 1of 30

CENTRAL BOARD OF SECONDARY EDUCATION

Computer Science (083)


Practical File

Submitted To: Submitted By:


Mr Abhishek Bhardwaj Rajiv Singh
TGT- Computer Science Sch No. : 5508
Class : XII-A
ACKNOWLEDGEMENT

I wish to express my deep sense of gratitude and indebtedness


to our learned teacher Mr Abhishek Bhardwaj, TGT- Computer
Science, Sainik School Chittorgarh for his invaluable help,
advice and guidance in the preparation of this practical file.

I am also greatly indebted to our Principal Col S Dhar, Offg


Vice Principal Maj Deepak Malik and school authorities for
providing me with the facilities and requisite laboratory
conditions for making this practical file.

I also extend my thanks to my parents, teachers, my


classmates and friends who helped me to complete this
practical file successfully.

Rajiv Singh
CERTIFICATE

This is to certify that Rajiv Singh, student of Class XII, Sainik


School Chittorgarh has completed the PRACTICAL FILE during
the academic year 2022-23 towards partial fulfillment of credit
for the Computer Science (083) practical evaluation of CBSE
and submitted satisfactory report, as compiled in the following
pages, under my supervision.

Internal Examiner External Examiner


Signature Signature
INDEX

Page
Ser Objective Signature
No
(i) Write a Python program to implement a stack using a list 1
data structure.
(ii) Create a student table with the student id, name, and marks 3
as attributes, where the student id is the primary key.
(iii) Insert the details of new students in the student table. 4
(iv) Delete the details of a student in the student table. 5
(v) Use the select command to get the details of the students 6
with marks more than 80.
(vi) Find the min, max, sum, and average of the marks in student 7
marks table.
(vii) Write a SQL query to display the marks without decimal 8
places, display the remainder after diving marks by 3 and
display the square of marks.
(viii) Write a SQL query to display names into capital letters, small 9
letters, display first 3 letters of name, display last 3 letters of
name, display the position the letter A in name.
(ix) Display today's date. Also display the date after 10 days 10
from current date.
(x) Display dayname, monthname, day, dayname, day of month, 11
day of year for today's date.
(xi) Write a Python program to check Successful connection with 12
MySQL.
(xii) Write a Python program to insert data into student table 13
created in MySQL.
(xiii) Write a Python program to update data into student table 15
created in MySQL.
(xiv) Write a Python program to fetch all data from student table 16
created in MySQL.
(xv) Write a Program in Python to Read a text file’s first 30 bytes 18
and printing it.
(xvi) Write a Program in Python to display the size of a text file 19
after removing EOL (/n) characters, leading and trailing white
spaces and blank lines.
(xvii) Write a Program in Python to create a text file with some 20
names separated by newline characters without using write()
function.
(xviii) Write a Program in Python to Read, Write (Multiple Records) 21
& Search into Binary File (Structure : Nested List)
(xix) Write a Program in Python to create & display the contents 23
of a CSV file with student record (Roll No., Name and Total
Marks).
(xx) Write a Program in Python to search the record of students, 25
who have secured above 90% marks in the CSV file created
in last program (Program No 14).
Objective 1 :

Write a Python program to implement a stack using a list data


structure.

Program Code:

def push(a,val):
a.append(val)
def pop(a):
item=a.pop()
print("Popped Item = ",item)
def peek(a):
last=len(a)-1
print("Peek Element = ",a[last])
def display(a):
for i in range(len(a)-1,-1,-1):
print(a[i])

#__main()__
a=[]
while True:
choice=int(input("1->Push\n2->Pop\n3->Peek\n4->Display\n5-
>Exit\nEnter Your Choice : "))
if choice==1:
val=int(input("Enter Element to Push : "))
push(a,val)
print("Element Pushed Successfully...")
elif choice==2:
if len(a)==0:
print("Stack Underflow...")
else:
pop(a)
elif choice==3:
if len(a)==0:
print("Stack Underflow...")
else:
peek(a)
elif choice==4:
if len(a)==0:
print("Stack Underflow...")
else:
display(a)
else:
break

5508 1
Output:

5508 2
Objective 2 :
Create a student table with the student id, name, and marks as
attributes, where the student id is the primary key.

Query:
CREATE TABLE STUDENT
(STUDENTID INTEGER PRIMARY KEY,
NAME VARCHAR(20) NOT NULL,
MARKS DECIMAL(5,2)
);

Result:

5508 3
Objective 3 :
Insert the details of new students in the student table.

Query:
INSERT INTO STUDENT
VALUES(5501,"MITWAY NAGAR",408);

Result:

5508 4
Objective 4 :
Delete the details of a student in the student table.
Query:

> DELETE FROM STUDENT


-> WHERE STUDENT_ID=5501;

Result:

5508 5
Objective 5 :

Use the select command to get the details of the students with marks
more than 80.
Query:
> SELECT * FROM STUDENT
-> WHERE MARKS>80;
Result:

5508 6
Objective 6 :
Find the min, max, sum, and average of the marks in student marks
table.
Query:
SELECT MAX(MARKS), MIN(MARKS), SUM(MARKS), AVG(MARKS)
FROM STUDENT;
Result:

5508 7
Objective 7 :
Write a SQL query to display the marks without decimal places, display the
remainder after diving marks by 3 and display the square of marks.
Query:
select round(marks,0),mod(marks,3),pow(marks,2)from student;
Result:

5508 8
Objective 8 :
Write a SQL query to display names into capital letters, small letters, display first 3
letters of name, display last 3 letters of name, display the position the letter A in
name.
Query:
select
ucase(name),lcase(name),left(name,3),right(name,3),instr(name,"a")fro
m student;
Result:

5508 9
Objective 9 :
Display today's date. Also display the date after 10 days from current date.

Query:
select curdate(),date_add(curdate(),interval 10 day);

Result:

5508 10
Objective 10 :
Display dayname, monthname, day, day of month, day of year for today's date.

Query:
select
monthname(curdate()),dayname(curdate()),day(curdate()),dayofmonth(c
urdate()),dayofyear(curdate());

Result:

5508 11
Objective 11 :
Write a Python program to check Successful connection with MySQL.
Program Code:

import mysql.connector as c
con=c.connect(host="localhost",
user="root",
passwd="12345",
database="employee")
if con.is_connected():
print("connection seccessful..")

Output:

5508 12
Objective 12 :
Write a Python program to insert data into student table created in MySQL.
Program Code:

import mysql.connector as c
con=c.connect(host="localhost",
user="root",
passwd="12345",
database="employee")
cur=con.cursor()
while True:
std_id=int(input("enter the number:"))
std_name=input("enter the name:")
std_class=int(input("enter the class:"))
std_section=input("enter the section:")
query="insert into std
values({},'{}',{},'{}')".format(std_id,std_name,std_class,std_
section)
cur.execute(query)
con.commit()
print("data inserted successfully...")
choice=input("y->more records\nn->exit\nenter choice:")
if choice=='n':
break

Input:

enter the number:107

enter the name:kush

enter the class:12

enter the section:A

data inserted successfully...

5508 13
Output:

5508 14
Objective 13 :

Write a Python program to update data into student table created in MySQL.

Input:

enter the number:106

enter the section:B

Output:

Data
updated

5508 15
Objective 14 :
Write a Python program to fetch all data from student table created in MySQL.
Program Code:

import mysql.connector as c
con=c.connect(host="localhost",
user="root",
passwd="12345",
database="employee")
cur=con.cursor()
query="select * from std"
cur.execute(query)
data=cur.fetchall()
for i in data:
print("fetched record is:",i)
print("total no. of row count :",cur.rowcount)

Output:

5508 16
INPUT TEXT FILE FOR PROGRAM NO. 15 & 16

I am student of

Sainik school chittorgarh

currently studying in class 12th

I want to be a Army officer

that's why i want to join NDA

now i am a part of chittorian fertinty

5508 17
PROGRAM - 15

Objective:
Write a Program in Python to Read a text file’s first 30 bytes and printing it.
Program Code:
fobj=open(r'd:\new folder\ssc.txt')
val=fobj.read(30)
print(val)
fobj.close()
Output:

5508 18
PROGRAM - 16

Objective:
Write a Program in Python to display the size of a text file after removing EOL (/n)
characters, leading and trailing white spaces and blank lines.
Program Code:

fobj=open('ssc.txt',"r")
str=' '
tsize=0
size=0
while str:
str=fobj.readline()
tsize=tsize+len(str)
size=size+len(str.strip())
print("total size of the file:",tsize)
print("size of file after removing:",size)
fobj.close()

Output:

5508 19
PROGRAM - 17

Objective:
Write a Program in Python to create a text file with some names separated by
newline characters without using write() function.
Program Code:

fileobj=open("student.txt","w")
L=[]
for i in range(5):
name=input("enter the name of student:")
L.append(name+'\n')
fileobj.writelines(L)
fileobj.close()

Output:

5508 20
PROGRAM - 18

Objective:
Write a Program in Python to Read, Write (Multiple Records) & Search into Binary
File (Structure : Nested List)
Program Code:

import pickle
def write():
fobj=open("cs.dat","wb")
record=[]
while True:
roll=int(input("enter the roll_no:"))
name=input("enter name:")
marks=int(input("enter total marks:"))
rec=[roll,name,marks]
record.append(rec)
choice=input("enter more records:Y/N? :")
if choice=='N':
break
pickle.dump(record,fobj)
print("data stored successfully..")
fobj.close()
def read():
fobj=open("cs.dat","rb")
f=pickle.load(fobj)
for i in f:
print(i)
fobj.close()
def search():
fobj=open("cs.dat","rb")
rollno=int(input("enter Roll no. to search:"))
flag=0
r=pickle.load(fobj)
for i in r:
if int(i[0])==rollno:
print(i)
flag=1
break
if flag==0:
print("please enter correct roll no.")
write()
read()
search()

5508 21
Output:

5508 22
PROGRAM - 19

Objective:
Write a Program in Python to create & display the contents of a CSV file with student
record (Roll No., Name and Total Marks).
Program Code:

import csv
def create():
with open("student.csv","w",newline='') as fobj:
objw=csv.writer(fobj)
objw.writerow(['roll_no','total marks'])
while True:
roll=int(input("enter roll number="))
name=input("enter name=")
total=int(input("enter total marks="))
record=[roll,name,total]
objw.writerow(record)
choice=int(input("1->enter more\n2->exit\nenter choice:"))
if choice==2:
break
def display():
with open("student.csv","r") as fobj:
objread=csv.reader(fobj)
for i in objread:
print(i)

create()
display()

5508 23
Output:

5508 24
PROGRAM - 20

Objective:
Write a Program in Python to search the record of students, who have secured
above 90% marks in the CSV file created in last program .
Program Code:

import csv
def display():
with open("student.csv","r") as fobj:
objread=csv.reader(fobj)
for i in objread:
print(i)
def search():
with open("student.csv","r")as fobj:
objread=csv.reader(fobj)
next(objread)
for i in objread:
if int(i[2])>=90:
print("\nStudent secured above 90% is : ",i)
display()
search()

Output:

5508 25

You might also like