0% found this document useful (0 votes)
115 views28 pages

Computer Science Computer Science (083) (083) : Practical File

The document is Panchdev Singh Yadav's computer science practical file submitted to his teacher Mr. Abhishek Bhardwaj, which contains programs and queries written by Panchdev to fulfill the objectives of the practical evaluation. The file includes programs on stacks, SQL queries to manipulate a student database table, programs to read and write files, and programs connecting Python to MySQL. Panchdev has signed each objective to verify its completion under the supervision of his internal and external examiners.

Uploaded by

Jsjsjj
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)
115 views28 pages

Computer Science Computer Science (083) (083) : Practical File

The document is Panchdev Singh Yadav's computer science practical file submitted to his teacher Mr. Abhishek Bhardwaj, which contains programs and queries written by Panchdev to fulfill the objectives of the practical evaluation. The file includes programs on stacks, SQL queries to manipulate a student database table, programs to read and write files, and programs connecting Python to MySQL. Panchdev has signed each objective to verify its completion under the supervision of his internal and external examiners.

Uploaded by

Jsjsjj
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/ 28

CENTRAL BOARD OF SECONDARY EDUCATION

Computer Science (083)


Practical File

Submitted To: Submitted By:


Mr Abhishek Bhardwaj Panchdev Singh Yadav
PGT- Computer Science Roll No. : 11648772
Class : XII--A

Panchdev Singh Yadav 11648772


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.

Panchdev Singh Yadav

Panchdev Singh Yadav 11648772


CERTIFICATE

This is to certify that Panchdev Singh Yadav , student of Class


XII, Sainik School Chittorgarh has completed the PRACTICAL
FILE during the academic year 2023-24 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

Panchdev Singh Yadav 11648772


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 last program.

Panchdev Singh Yadav 11648772


Panchdev Singh Yadav 11648772
Objective 1 :

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


structure.

Query:

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

Panchdev Singh Yadav 11648772


Output:

Panchdev Singh Yadav 11648772


Objective 2 :

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

Query:

mysql> create table student(


-> student_id int primary key,
-> name char(40) not null,
-> marks int );
Query OK, 0 rows affected (0.09 sec)

Output:

Panchdev Singh Yadav 11648772


Objective 3 :

Insert the details of new students in the student table.

Query:

mysql> INSERT INTO STUDENT


-> VALUES(6019,"SHIVANSHU",83),
-> (5981,"PANCHDEV",99),
-> (6034,"KRISHAN",100),
-> (5662,"LUCKY",001),
-> (5648,"VISHESH",33);
Query OK, 5 rows affected (0.02 sec)
Records: 5 Duplicates: 0 Warnings: 0

Output:

Objective 4 :

Panchdev Singh Yadav 11648772


Delete the details of a student in the student table.

Query:
mysql> DELETE FROM STUDENT
-> WHERE STUDENT_ID=5981;
Query OK, 1 row affected (0.01 sec)

Output:

Objective 5 :

Panchdev Singh Yadav 11648772


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

Query:
mysql> SELECT * FROM STUDENT
-> WHERE MARKS > 80;

Output:

Objective 6 :

Panchdev Singh Yadav 11648772


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

Query:

mysql> SELECT MIN(MARKS),MAX(MARKS),SUM(MARKS),AVG(MARKS) FROM


STUDENT;

Output:

Objective 7 :

Panchdev Singh Yadav 11648772


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:
mysql> select *,truncate(marks,0) as
marks_without_decimal,marks*marks as square,mod(marks,3) as
remainder from student;

Output:

Objective 8 :

Panchdev Singh Yadav 11648772


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:
mysql> select *,upper(name) as upper_name,

-> lower(name) as lower_name,

-> substring(name,1,3) as first_3_letter,

-> substring(name,-3) as last_3_letter,

-> locate("A",name) as position_of_A from student;

Output:

Objective 9 :

Panchdev Singh Yadav 11648772


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

Query:

mysql> select current_date(),adddate(current_date(),10) as


date_after_10_days;

Output:

Objective 10 :

Panchdev Singh Yadav 11648772


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

Query:

mysql> select dayname(current_date()) as today_day,


-> day(current_date()) as today_date,
-> dayofmonth(current_date()) as month_date,
-> monthname(current_date()) as month_name,
-> dayofyear(current_date()) as year_name;

Output :

Program 11 :

Panchdev Singh Yadav 11648772


Write a Python program to check Successful connection with
MySQL.

Program code :

import mysql.connector
mydb = mysql.connector.connect(
host="localhost",
user="root",
port="3306",
password="1234",
database="fam")
if mydb.is_connected:
print("connection succesful")

Output:

Program 12 :

Panchdev Singh Yadav 11648772


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

Program code :

import mysql.connector
mydb = mysql.connector.connect(
host="localhost",
user="root",
port="3306",
password="1234",
database="fam")
l=[]
a=int(input("how many datas you want to enter:"))
for i in range(a):
student_id=int(input("enter student_id:"))
name=input("enter name:")
marks=int(input("enter marks :"))
b=[student_id,name,marks]
l.append(b)
mycursor = mydb.cursor()
for i in range(a):
query="insert into student values
({},'{}',{})".format(l[i][0],l[i][1],l[i][2])
mycursor.execute(query)
mydb.commit()
mycursor.execute("SELECT * FROM student")
myresult = mycursor.fetchall()
print("data in table are:" )
for x in list(myresult):
print("\t\t",x)

Output:

Panchdev Singh Yadav 11648772


Program 13 :

Panchdev Singh Yadav 11648772


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

Program code :

import mysql.connector
mydb = mysql.connector.connect(
host="localhost",
user="root",
port="3306",
password="1234",
database="fam")
a=int(input("enter student_id :"))
b=float(input("enter new marks:"))
mycursor = mydb.cursor()
query="update student set marks={} where
student_id={}".format(b,a)
mycursor.execute(query)
mydb.commit()
mycursor.execute("SELECT * FROM student")
myresult = mycursor.fetchall()
print("data in table are:" )
for x in list(myresult):
print("\t\t",x)

Output:

Program 14 :

Panchdev Singh Yadav 11648772


Write a Python program to fetch all data from student table created
in MySQL.

Program code :
import mysql.connector
mydb = mysql.connector.connect(
host="localhost",
user="root",
port="3306",
password="1234",
database="fam")
mycursor = mydb.cursor()
mycursor.execute("SELECT * FROM student")
myresult = mycursor.fetchall()
print("data in the table are :")
for x in myresult:
print("\t\t",x)
Output:

Panchdev Singh Yadav 11648772


Program 15 :

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


printing it.

Program code :

file=open("5981.txt","r")
a=file.read(30)
print(a)
file.close()

Output :

Panchdev Singh Yadav 11648772


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

f1 = open("5981.txt",'r')
data = f1.readlines()
content = ""
for i in data :
for j in i :
if j.isalnum():
content += j
print("file size:-",len(content),"bits")
f1.close()

Output :

Panchdev Singh Yadav 11648772


Program 17 :

Write a Program in Python to create a text file with some names


separated by newline characters without using write() function.

Program code :
file=open("6034.txt","w")
l=[]
a=int(input("write no. names you want to write :"))
for i in range(a):
print("enter name",i+1,":",end="")
x=input()
l.append(x+"\n")
file.writelines(l)
file.close()
file=open("6034.txt","r")
print("NAME SDDED IN FILE ARE :")
for i in file.readlines():
print("\t\t\t",i,end="")
file.close()

Output :

Panchdev Singh Yadav 11648772


Program 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 in 'nN':
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:
if int(i[0])==roll:
print(i)
flag=1
break
if flag==0:
print("enter correct roll no.")
write()
read()
search()

Panchdev Singh Yadav 11648772


Output :

Panchdev Singh Yadav 11648772


Program 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():
fobj=open("student.csv","w",newline='')
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 in 'nN':
break
def display():
fobj=open("student.csv","r")
objread=csv.reader(fobj)
for i in objread:
print(i)
create()
display()
Output :

Panchdev Singh Yadav 11648772


Program 20 :

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 search(data1):

data=data1[1:]

for i in range(len(data)):

a=int(data[i][2])

if a>= 90:

print(data[i])

fobj=open("student.csv","r")

objread=csv.reader(fobj)

data=list(objread)

print("data of student who scored more than 90%")

search(data)

Output :

Panchdev Singh Yadav 11648772

You might also like