0% found this document useful (0 votes)
69 views29 pages

Computer Science (083) : Practical File

Here is the program to update data into student table in MySQL: ```python import mysql.connector con = mysql.connector.connect( host="localhost", user="root", password="12345", database="kushians" ) cur = con.cursor() studentid = int(input("Enter student id: ")) marks = int(input("Enter new marks: ")) query = "UPDATE students SET marks = {} WHERE studentid = {}".format(marks, studentid) cur.execute(query) con.commit() print("Record updated successfully") ``` This program takes student id and new marks as input from

Uploaded by

satyam
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
69 views29 pages

Computer Science (083) : Practical File

Here is the program to update data into student table in MySQL: ```python import mysql.connector con = mysql.connector.connect( host="localhost", user="root", password="12345", database="kushians" ) cur = con.cursor() studentid = int(input("Enter student id: ")) marks = int(input("Enter new marks: ")) query = "UPDATE students SET marks = {} WHERE studentid = {}".format(marks, studentid) cur.execute(query) con.commit() print("Record updated successfully") ``` This program takes student id and new marks as input from

Uploaded by

satyam
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 29

+

CENTRAL BOARD OF SECONDARY EDUCATION

Computer Science (083)


Practical File

Submitted To: Submitted By:


Mr Abhishek Bhardwaj Vikas
TGT- Computer Science Roll No. : 5495
Class : XII-A

5495 Page 1
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.

Vikas

5495 Page 2
CERTIFICATE

This is to certify that Vikas 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 Signatue

5495 Page 1
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 3
marks 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 6
students with marks more than 80.
(vi) Find the min, max, sum, and average of the marks in 7
student 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, 9
small 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
10 days from current date.
(x) Display dayname, monthname, day, dayname, day of 11
month, day of year for today's date.
(xi) Write a Python program to check Successful connection 12
with 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 17
table created in MySQL.
(xv) Write a Program in Python to Read a text file’s first 30 20
bytes and printing it.
(xvi) Write a Program in Python to display the size of a text 21
file 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 23
Records) & Search into Binary File (Structure : Nested
List)
(xix) Write a Program in Python to create & display the 25
contents of a CSV file with student record (Roll No.,
Name and Total Marks).
(xx) Write a Program in Python to search the record of 27
students, who have secured above 90% marks in the

5495 Page 1
CSV file created in last program (Program No 14).

5495 Page 2
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 ("poped item=",item)
def peak (a):
last=len(a)-1
print("peak element:" , a [last])
def display (a):
for i in range (len(a)-1, -1,-1):
print (a[i])
a=[]
while True:
choice=int(input("1=push\n2=pop\n3=peak\n4=display\n5=exit\n enter
choice"))
if choice==1:
val=int(input("enter the element to push"))
push (a,val)
print ("element push into stack")
elif choice==2:
if len(a)==0:
print ("under flow error")
else:
pop(a)
elif choice==3:
if len(a)==0:
print("under flow error")
else:
peak(a)
elif choice==4:
if len(a)==0:
print("under flow error")
else:
display(a)
else:
break

5495 1
Output:

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

Objective 3 :

5495 3
Insert the details of new students in the student table.

Query:
INSERT INTO STUDENTS
VALUES(5564,'RAHUL',54);

Result:

Objective 4 :
Delete the details of a student in the student table.
5495 4
Query:
DELETE FROM STUDENTS
WHERE STUDENTID=5564;

Result:

Objective 5 :

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

Query:
SELECT * FROM STUDENTS
WHERE MARKS>80;

Result:

Objective 6 :

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

Query:
SELECT
MIN(MARKS),MAX(MARKS),SUM(MARKS),AVG(MARKS)
FROM STUDENTS;

Result:

Objective 7 :

5495 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)FRO
M STUDENTS;

Result:

Objective 8 :

5495 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(NA
ME,3),INSTR(NAME,"A")FROM STUDENTS;

Result:

Objective 9 :
5495 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:

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

Query:
SELECT
MONTHNAME(CURDATE()),DAYNAME(CURDATE()),DAY
(CURDATE()),DAYOFMONTH(CURDATE()),DAYOFYEAR(
CURDATE());

Result:

Objective 11 :
5495
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")
if con. is _connected():
print ("connected sucessfully")

Output:

Objective 12 : Write a Python program to insert data into student


table created in MySQL.
5495
12
Program Code
import mysql. connector as c

con=c.connect(host= "localhost",
user= "root" ,
passwd= "12345",
database= "kushians")
cur = con.cursor()
while True:
studentid=int(input("enter studentid:"))
name = input ("enter name:")
marks=int(input("enter marks"))
query = "INSERT INTO STUDENTS values ({}, '{}',
{} )".format( studentid, name, marks)
cur. execute (query)
con.commit()
print ("data instered sucessfully....")
choice=int(input("1->more records\n2->exit\n enter choice:"))
if choice==2:
break
Input:

Output:

5495
13
Objective 13 : Write a Python program to update data into student
table created in MySQL.

Input: import mysql. connector as c


con=c.connect(host= "localhost",
user= "root" ,
passwd= "12345",
database= "kushians")
cur = con.cursor()
studentid=int(input("enter studentid"))
marks=int(input("enter new marks of student:"))
query="update students set marks='{}' where
studentid={}".format(marks, studentid)
cur.execute(query)
con.commit()
if cur.rowcount>0:
print("data updated successfully....")
else:
print("no record found..")

Output:

5495
14
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= "kushians")
cursor = con.cursor()
query="select * from students"
cursor.execute(query)
record=cursor.fetchall()
for i in record:
print ("fetched record is : ",i)
print ("total no. of row count : ", cursor.
rowcount)

Output

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

PROGRAM - 15

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()

5495
16
Output:

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()

5495
17
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:

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 name of student : ")
L.append(name+'\n')
fileobj.writelines(L)
fileobj.close()
5495
18
Output:

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=[]

5495
19
while True:
roll=int(input("enter 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()

Output:

5495
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).

5495
21
Program Code: import csv
def create ():
with open ("student.csv", "w" , newline='') as fobj:
objw=csv.writer(fobj)
objw.writerow(['roll','name','total_marks'])
while True:
roll=int(input("enter roll_no.:"))
name=input("enter name:")
total_marks=int(input("enter marks"))
rec=[roll,name,total_marks]
objw.writerow(rec)
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:

5495
22
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 create():
with open ("st.csv","w",newline='') as obj:
fobj=csv.writer(obj)
fobj.writerow(['roll', 'name','total_marks'])
while True:
roll=int(input("enter roll_no.:"))
name=input("enter name:")
total_marks=int(input("enter marks"))
rec=[roll,name,total_marks]
fobj.writerow(rec)
choice=input("enter more records y/n?:")
if choice=="n":
break
def search ():
max=0
with open("st.csv","r")as obj:
fobj=csv.reader(obj)
next(fobj)
for i in fobj:
if int (i[2])>int(max):
max=i[2]
r=i[0]

create()
search()

5495
23
Output:

5495
24

You might also like