Harshit Project

You might also like

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 28

CENTRAL BOARD OF SECONDARY EDUCATION

Computer Science (083)


Practical File

Submitted To: Submitted By:


Mr AbhishekBhardwaj Cdt Aadharsh Singh
TGT- Computer Science Sch. No. : 5573
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
forproviding 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 tocomplete this practical file
successfully.

Cdt Aadharsh Singh


CERTIFICATE

This is to certify that, I Cdt Aadharsh Singh student of Class


XII, Sainik School Chittorgarh hascompleted the PRACTICAL
FILE during theacademic year 2022-23 towards partial
fulfillmentof credit for the Computer Science (083)
practicalevaluation of CBSE and submitted satisfactory
report,as compiled in the following pages, under mysupervision.

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
asattributes, 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 14
created in MySQL.
(xiv) Write a Python program to fetch all data from student table 15
created in MySQL.
(xv) Write a Program in Python to Read a text file’s first 30 bytes 17
and printing it.
(xvi) Write a Program in Python to display the size of a text file 18
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 19
names separated by newline characters without using write()
function.
(xviii) Write a Program in Python to Read, Write (Multiple Records) 20
& Search into Binary File (Structure : Nested List)
(xix) Write a Program in Python to create & display the contents 22
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, 23
who have secured above 90% marks in the CSV file created
in last program (Program No 14).
Objective1:

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:
iflen(a)==0:
print("Stack Underflow...")
else:
pop(a)
elif choice==3:
iflen(a)==0:
print("Stack Underflow...")
else:
peek(a)
elif choice==4:
iflen(a)==0:
print("Stack Underflow...")
else:
display(a)
else:
break

5597 1
Output:

5597 2
Objective2:
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:

5597 3
Objective3:
Insert the details of new students in the student table.

Query:

INSERT INTO STUDENT


VALUES(5597,’HARSHIT’,98);

Result:

5597 4
Objective4:
Delete the details of a student in the student table.

Query:

DELETE FROM STUDENT


WHERE STUDENTID=5618;

Result:

Objective5:

5597 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:

Objective6:

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

Query:

Selectmin(marks),max(marks),sum(marks),avg(marks) from student;

Result:

Objective7:

5597 7
Write a SQL query to display the marks without decimal places, display
the remainder after dividing marks by 3 and display the square of marks.

Query:

select round(marks,0),mod(marks,3),pow(marks,2) from student;

Result:

Objective8:

5597 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:

Selectucase(name),lcase(name),left(name,3),right(name,3),
instr(name,"a") from student;

Result:

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

Query:

Selectcurdate() date_add(curdate(),interval 10 day );

Result:

Objective10:

5597 10
Display dayname, monthname, day, dayname, day of month, day of year
for today's date.

Query:
select dayname(now()),monthname(now()),day(now()),dayname(now()),
dayofmonth(now()),dayofyear(now());

Result:

Objective11:

5597 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="student")
ifcon.is_connected():
print("successfully connected")
Output:

Objective12:

5597 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="mohit")
cur=con.cursor()
STUDENTID=int(input("Enter student id : "))
NAME=input("Enter name of student : ")
MARKS=int(input("Enter the MARKS : "))
query="INSERTINTOSTUDDENTVALUES({},'{}',{})".format
(STUDENTID,NAME,MARKS)
cur.execute(query)
con.commit()
con.close()
print("data inserted successfully....")
Input:

Output:

Objective13:

5597 13
Write a Python program to update data into student tablecreated in
MySQL.

Input:

Output:

Objective14:

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

Output:

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

PROGRAM – 15

5597 16
Objective: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:

PROGRAM – 16

5597 17
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
whilestr:
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

PROGRAM – 17

5597 18
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 : ")
L.append(name+'\n')
fileobj.writelines(L)

Output:

PROGRAM – 18

5597 19
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 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")
roll=int(input("enter roll no. to search"))
flag=0
r=pickle.load(fobj)
for i in r:
ifint(i[0])==roll:
print(i)
flag=1
break
if flag==0:
print("enter coreect roll")
write()
read()
search()

Output:
5597 20
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).

5597 21
Program Code:
importcsv
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()

Output:

PROGRAM – 20

5597 22
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 No 14).

Program Code:
importcsv
def create():
with open("student.csv","w",newline='')as obj:
fobj=csv.writer(obj)
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. to search"))
with open("student.csv","r")as obj:
flag=0
fobj=csv.reader(obj)
next(fobj)
for i in fobj:
ifint(i[0])==roll:
print(i,'\n')
flag=1
break
if flag==0:
print("entered roll no.:",roll,"not found")
create()
search()

Output:

5597 23
5597 24

You might also like