Computer Science (083) : Practical File
Computer Science (083) : Practical File
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
places, display the remainder after diving marks by 3 and 8
display the square of marks.
(viii) Write a SQL query to display names into capital letters, small
letters, display first 3 letters of name, display last 3 letters of 9
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
after removing EOL (/n) characters, leading and trailing white 21
spaces and blank lines.
(xvii) Write a Program in Python to create a text file with some
names separated by newline characters without using write() 22
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
of a CSV file with student record (Roll No., Name and Total 25
Marks).
(xx) Write a Program in Python to search the record of students,
who have secured above 90% marks in the CSV file created 27
in last program.
Objective1:
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
5823 Page 1
Output:
5823 Page 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
-> STUDENT_ID INTEGER(10) PRIMARY KEY,
-> NAME VARCHAR(50) NOT NULL,
-> MARKS DECIMAL(10,2));
Output:
Objective 3:
5823 Page 3
Insert the details of new students in the student table.
Query:
INSERT INTO STUDENT
->VALUES(6213,'Prince',92.55),
-> (6120,'Karan',95.25),
-> (5741,'Jitendra',93.76),
-> (5753,'Rahul',90.85),
-> (5728,'Prameet',74.65),
-> (5758,'Akhilesh',84.36),
-> (5812,'Tejash',98.44);
Output:
5823 Page 4
Objective 4:
Query:
DELETE FROM STUDENT
-> WHERE STUDENT_ID=5619;
Output:
5823 Page 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>90;
Output:
5823 Page 6
Objective 6:
Find the min, max, sum, and average of the marks in student marks
table.
Query:
SELECT MIN(MARKS),
MAX(MARKS),
AVG(MARKS),
SUM(MARKS) FROM STUDENT;
Output:
5823 Page 7
Objective 7:
Query:
SELECT TRUNCATE(MARKS,0),
MOD(MARKS,3),
POW(MARKS,2) FROM STUDENT;
Output:
5823 Page 8
Objective 8:
Query:
SELECT UPPER(NAME),
LOWER(NAME),
LEFT(NAME,3),
RIGHT(NAME,3),
INSTR(NAME,"A") FROM STUDENT;
Output:
5823 Page 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);
Output:
5823 Page 10
Objective 10:
Query:
SELECT DAY(NOW()),
DAYNAME(NOW()),
MONTHNAME(NOW());
SELECT DAYOFMONTH(NOW()),
DAYOFYEAR(NOW()),
YEAR(NOW());
Output:
5823 Page 11
Objective 11:
Program Code:
importmysql.connector as c
con=c.connect(host="localhost",
user="root",
passwd="1234",
port="3306")
ifcon.is_connected:
print("Connection Successful")
Output:
5823 Page 12
Objective 12:
Program Code:
importmysql.connector as c
con=c.connect(host="localhost",user="root",
passwd="1234",database="school")
cur=con.cursor()
Student_ID=int(input("Enter the Student_ID :"))
Name=input("Enter the Name of Student :")
Marks=float(input("Enter the marks of Student :"))
query="INSERT INTO STUDENT VALUES ({},'{}',
{})".format(Student_ID,Name,Marks)
cur.execute(query)
con.commit()
con.close()
print("Data Inserted Successfully.........")
5823 Page 13
Output:
5823 Page 14
Objective 13:
Program Code:
importmysql.connector as c
con=c.connect(host="localhost",user="root",passwd="1234",datab
ase="school")
cur=con.cursor()
Student_ID=int(input("Enter the Student_ID :"))
Name=input("Enter the Name of Student :")
Marks=float(input("Enter the marks of Student :"))
query="UPDATE STUDENT SET Name='{}',Marks={} WHERE
Student_ID={}".format(Name,Marks,Student_ID)
cur.execute(query)
con.commit()
con.close()
print("Data updated Successfully.........")
5823 Page 15
Output:
5823 Page 16
Objective 14:
Write a Python program to fetch all data from student table created
in MySQL.
Program Code:
importmysql.connector as c
con=c.connect(host="localhost",
password="1234",
user="root",
port="3306",
database="SCHOOL")
query="SELECT * FROM STUDENT"
cur=con.cursor()
cur.execute(query)
data=list(cur)
fori,j,k in data:
print(i,j,k)
5823 Page 17
Output:
5823 Page 18
Objective 15:
Program Code:
fobj=open('ssc.txt')
val=fobj.read(30)
print(val)
fobj.close()
Output:
5823 Page 19
Objective16:
Program Code:
fobj=open("ssc.txt",'r')
data=fobj.read()
count=0
for i in data :
if i!="\n":
count+=1
print( "Total Count Of Character :",count)
Output:
5823 Page 20
Objective17:
Program Code:
fobj=open("text.txt",'w',newline='\n')
while True:
choice=input("Press Q to quit:")
if choice=="Q":
break
else:
name=input("Enter the name :")
fobj.writelines(name)
fobj.close()
Output:
5823 Page 21
Objective18:
Write a Program in Python to Read, Write (Multiple Records) &
Search into Binary File (Structure : Nested List)
Program Code :
import pickle
fobj = open("text.dat",'wb')
L=[]
while True:
choice=input("Press Q to quit:")
if choice!="Q":
name=input("Enter the name : ")
clas=input("Enter the Class : ")
marks=int(input("Enter The Marks : "))
L1=[name,clas,marks]
L.append(L1)
else:
break
pickle.dump(L,fobj)
print("Data FeededSuccesfully")
fobj.close()
fobj = open("text.dat",'rb')
data=pickle.load(fobj)
print(data)
for i in data:
ifint(i[2])>90:
print(i)
fobj.close()
Output:
5823 Page 22
Objective 19:
Program Code :
importcsv
students = []
while True:
choice=input("Press Q to quit:")
if choice!="Q":
name=input("Enter the Roll No. : ")
clas=input("Enter the Name : ")
Output:
5823 Page 23
Objective 20:
Query :
importcsv
with open('students.csv', 'r') as file:
reader = csv.reader(file)
next(reader)
for row in reader:
ifint(row[2]) >= 90:
print(f"{row[0]} has scored {row[1]} marks.")
Output:
5823 Page 24
5823 Page 25