0% found this document useful (0 votes)
58 views33 pages

Prameet (12a) (5728)

This document is a practical file for Computer Science (083) submitted by Prameet, a Class XII student at Sainik School Chittorgarh. It includes acknowledgments, a certificate of completion, an index of programming objectives, and detailed Python and SQL code implementations for various tasks related to data structures and database management. The practical file serves as a record of the student's work and learning in the subject during the academic year 2024-25.

Uploaded by

samradhasingh79
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)
58 views33 pages

Prameet (12a) (5728)

This document is a practical file for Computer Science (083) submitted by Prameet, a Class XII student at Sainik School Chittorgarh. It includes acknowledgments, a certificate of completion, an index of programming objectives, and detailed Python and SQL code implementations for various tasks related to data structures and database management. The practical file serves as a record of the student's work and learning in the subject during the academic year 2024-25.

Uploaded by

samradhasingh79
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
You are on page 1/ 33

CENTRAL BOARD OF SECONDARY EDUCATION

Computer Science (083)


Practical File

Submitted To: Submitted By:


Mr Abhishek Bhardwaj Prameet
PGT- Computer Science Roll No. :
Class : XII-A
ACKNOWLEDGEMENT

I wish to express my deep sense of gratitude and indebtedness


to our learned teacher Mr Abhishek Bhardwaj, PGT- 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 ADS Jasrotia,


Vice Principal Lt Col Parul Srivastava 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.

PRAMEET
CERTIFICATE

This is to certify that PRAMEET, student of Class XII, Sainik


School Chittorgarh has completed the PRACTICAL FILE during
the academic year 2024-25 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 17
created in MySQL.
(xv) Write a Program in Python to Read a text file’s first 30 bytes 20
and printing it.
(xvi) Write a Program in Python to display the size of a text file 21
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 22
names separated by newline characters without using write()
function.
(xviii) Write a Program in Python to Read, Write (Multiple Records) 23
& Search into Binary File (Structure : Nested List)
(xix) Write a Program in Python to create & display the contents 25
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, 27
who have secured above 90% marks in the CSV file created
in program number (xix).
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:

1
5728
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

2
5728
Output:

3
5728
Objective 2 :

Create a student table with the student id, name, and marks as

attributes, where the student id is the primary key.

Program Code:
CREATE TABLE STUDENT
(STUDENT_ID INTEGER PRIMARY KEY,
NAME VARCHAR(40) NOT NULL,
MARKS DECIMAL NOT NULL);

Output:

4
5728
Objective 3 :

Insert the details of new students in the student table.

Program Code:
INSERT INTO STUDENT
VALUES(5728,’PRAMEET’,87);

Output:

5
5728
Objective 4:

Delete the details of a student in the student table.

Program Code:
DELETE FROM STUDENT
WHERE STUDENTID=5728;

Output:

6
5728
Objective 5 :

Use the select command to get the details of the students with
marks more than 80.

Program Code:
SELECT * FROM STUDENT
WHERE MARKS>80;

Output:

7
5728
Objective 6 :

Find the min, max, sum, and average of the marks in student marks
table.

Program Code:
Selectmin(marks),max(marks),sum(marks),avg(marks)
from student;

Output:

8
5728
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.

Program Code:
Select round(marks,0),mod(marks,3),pow(marks,2)
from student;

Output:

9
5728
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.

Program Code:
SELECT UCASE(NAME), LCASE(NAME), LEFT(NAME,3),
RIGHT(NAME,3), INSTR(NAME,"A") FROM STUDENT;

Output:

10
5728
Objective 9 :

Display today's date. Also display the date after 10 days from
current date.

Program Code:
SELECT CURDATE(),DATE_ADD(CURDATE(),INTERVAL 10 DAY);

Output:

11
5728
Objective 10 :

Display dayname, monthname, day, dayname, day of month, day of


year for today's date.

Program Code:
SELECT DAYNAME(NOW()), MONTHNAME(NOW()), DAY(NOW()),
DAYNAME(NOW()), DAYOFMONTH(NOW()), DAYOFYEAR(NOW());

Output:

12
5728
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="1234",
database="school")
if con.is_connected():
print("successfully connected")

Output:

13
5728
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="1234",
database="school")
cur=con.cursor()
STUDENT_ID=int(input("Enter student_id : "))
NAME=input("Enter name of student : ")
MARKS=int(input("Enter the MARKS : "))
query="INSERT INTO STUDENT
VALUES({},'{}',{})".format(STUDENT_ID,NAME,MARKS)
cur.execute(query)
con.commit()
con.close()
print("data inserted successfully....")

14
5728
Output:

15
5728
Objective 13 :

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


MySQL.

Program Code:
import mysql.connector as c
con=c.connect(host="localhost",
user="root",
passwd="1234",
database="school")
cur=con.cursor()
STUDENT_ID=int(input("Enter the stuendt_ID to be
updated\n:- "))
MARKS=int(input("Enter the correct Marks\n:- "))
query="UPDATE STUDENT SET MARKS={} WHERE
STUDENT_ID={}".format(MARKS,STUDENT_ID)
cur.execute(query)
con.commit()
if cur.rowcount>0:
print("Data Updated Successfully...")

16
5728
Output:

17
5728
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="1234",
database="school")
cursor=con.cursor()
cursor.execute("select * from student")
data=cursor.fetchall()
for i in data:
print("FETCHED RECORD IS : ",i)
print("Total no. of row count : ",cursor.rowcount)

Output:

18
5728
INPUT TEXT FILE FOR PROGRAM NO. 15 & 16

19
5728
Objective 15 :

Write a Program in Python to Read a text file’s first 30 bytes and


printing it.

Program Code:
fobj=open("ssc.txt")
val=fobj.read(30)
print(val)
fobj.close

Output:

20
5728
Objective 16 :

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 a file:",tsize)
print("size of file after removing:",size)
fobj.close()

Output:

21
5728
Objective 17 :

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 : ")
L.append(name+'\n')
fileobj.writelines(L)
fileobj.close()
print("Data Entered")

Output:

22
5728
Objective 18 :

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 the name")
marks=int(input("enter the 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")

23
5728
roll=int(input("enter roll no. to search"))
flag=0
r=pickle.load(fobj)
for i in r:
if int(i[0])==roll:
print(i)
flag=1
break
if flag==0:
print("enter correct roll")
write()
read()
search()

Output:

24
5728
Objective 19 :

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','name','marks'])
while True:
roll=int(input("enter the roll no.:"))
name=input("enter the name:")
marks=int(input("enter the marks:"))
record=[roll,name,marks]
objw.writerow(record)
choice=input("enter more records Y|N?")
if choice=='N':
break
def display():
with open("student.csv","r")as fobj:
objread=csv.reader(fobj)
for i in objread:
print(i)
create()
display()

25
5728
Output:

26
5728
Objective 20 :

Write a Program in Python to search the record of students, who


have secured above 90% marks in the CSV file created in program
number (xix).

Program Code:
import csv
def create():
with open("student.csv","w",newline='')as fobj:
fobj=csv.writer(fobj)
fobj.writerow(['roll','name','marks'])
while True:
roll=int(input("enter the roll no.:"))
name=input("enter the name:")
marks=int(input("enter the marks:"))
rec=[roll,name,marks]
fobj.writerow(rec)
choice=input("enter more records Y|N?")
if choice=='N':
break
def search():
roll = int(input("enter the roll no.:"))
with open("student.csv","r")as fobj:
flag=0
fobj=csv.reader(fobj)
next(fobj)
with open("student.csv","r")as fobj:
flag=0
fobj=csv.reader(fobj)

27
5728
next(fobj)
for i in fobj:
if int(i[0])==roll:
print(i,'\n')
flag=1
break
if flag==0:
print("entered roll no.:",roll,"not
found")
create()
search()

Output:

28
5728

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy