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

Kovaipudur, Coimbatore – 641042

Affiliation No: 1930510

PRACTICAL FILE
for

AISSCE 2022 Examination


[As a part of the Computer Science Course (083)]

Submitted by:

Darsh Marothi
[Reg No. ___________]

Under the Guidance of:

Ms. Akhila B
PGT (CSc)
………………………………… …………………………………..

Signature of Internal Examiner Signature of External Examiner

1
CERTIFICATE

Certified that this is the bonafide record of the practical


work in Computer Science done by Darsh Marothi (Reg
No: ____________) and is submitted for the Practical
Examination at CS Academy, Coimbatore on
_____________________.

……….…………………

Signature of Principal

(Mr. Neil Guha)

………………………………… …………………………………..

Signature of Internal Examiner Signature of External Examiner

2
INDEX
Write a program to implement all the basic operations of a stack.
1. (push, pop, peak, etc.) and show the outputs.

Write a program to display the vowels present in a given word using


2. stacks.

MYSQL
To create a table “student” with the following fields - S.No., Admin
1. No., Name of student, City, Maths Physics, Chemistry and display
the table. Then execute the following commands

Create a table Employee and use the “group by” clause, to find the
2. minimum, maximum, sum of salary and count and average for an
employee table and department table.
MYSQL CONNECTOR/PYTHON

Write a program to connect with database and store record of


1. employee and display records.

Write a program to create student table which contains 5 students


2. details and display first three rows student table of MySQL database
“test”.

Write a program to connect with database and search employee


3. number in table employee and display record, if employee number
not found, displaying appropriate message.

Write a program to connect with database and update the employee


4. record related with the employee number entered by the user.

Write a program to connect with database and delete the record of


5. the entered employee number.

Basic Operations of Stack

3
Question:
Write a program to implement all the basic operations of a stack. (push, pop,
peak, etc.) and show the outputs.

Aim:
To Write a program to implement all the basic operations of a stack. (push, pop,
peak, etc.) and show the outputs.

Program:
def push(s,i):
s.append(i)
t=len(s)-1
print(s)

def pop(s):
x=s.pop()
if len(s)==0:
top=None
else:
top=len(s)-1
return x

s=[]
top=None
ch='y'
while True:
print("enter 1 to push,enter 2 to pop:")
u=input("enter choice:")

if u=='1':
n=int(input("enter item:"))
push(s,n)
elif u=='2':
y=pop(s)
print("item popped:",y)
else:

4
break

Ouput:

Result:
The above program has been executed and the required output has been
obtained.

5
Vowels In A Stack

Question: Write a program to display the vowels present in a given word using
stacks.

Aim: To write a program to display the vowels present in a given word using
stacks.

Program:

def push(s,i):
s.append(i)

s=[]
top=None
n=input("enter word:")
for i in range(len(n)):
if n[i]=='a' or n[i]=='A' or n[i]=='e' or n[i]=='E' or n[i]=='i' or n[i]=='I' or
n[i]=='o' or n[i]=='O' or n[i]=='u' or n[i]=='U':
push(s,n[i])
print("Vowels present in the word:",s)

Output:

Result:
The above program has been executed and the required output has been
obtained.

6
MySQL
Question:
To create a table “student” with the following fields - S.No., Admin No., Name
of student, City, Maths , Physics, Chemistry and display the table. Then execute
the following commands:

(i) Display records of students who have scored more than 90 in Maths.

Program:
Select * from student where Maths >90;

Output:

(ii) Display records of students whose names start with the letter 'A'.

Program:
Select * from student where Name Like ‘A%’;

Ouput:

7
(iii) Display the records of the students whose name's fourth letter is 'e'.

Program:
Select * from student where Name Like ‘___e%’;

Output:

(iv) Arrange the records in descending order by student name.

Program:
Select * from student order by Name desc;

Output:

8
(v) Increase the marks by 2 in Physics for students who secured 80.

Program:
Update student set Physics=Physics+2 where Physics=80;

Output:

(vi) Display the names of the students who reside in Coimbatore.

Program:
Select * from student where City =’Coimbatore’;

Output:

9
(iv) Change the size at 'Name of student' column from 30 to 40.

Program:
Alter table student modify Name varchar(40);

Output:

(v) Display the total Math marks of all students and also display the
average.

Program:
Select sum(Maths), avg(Maths) from student;

Output:

10
(vi) Display the record with maximum marks in Physics.

Program:
Select Max(Physics) from student;

Output:

(vii) Write a command to delete any record from the table.

Program:
Delete from student where Name=’Ajay’;

Output:

(viii) Write a command to show a list of databases.

Program:
Show databases;

11
Output:

(ix) Write a command to show the tables inside a database.

Program:
Show tables;

Output:

(x) Write a command to describe the structure of the table.

Program:
Use <databasename>;
Desc <tablename>;

12
Output:

(xi) Write a command to drop the table.

Program:

Drop table <tablename>;

Output:

13
Create and Display
Question: Create a table Employee and use the “group by” clause, to find the
minimum, maximum, sum of salary and count and average for an employee
table and department table.

Aim: To create a table Employee and use the “group by” clause, to find the
minimum, maximum, sum of salary and count and average for an employee
table and department table and display the output.

Program and table created:

(i) Minimum Salary :

Code: select Emp_id,Emp,name,Emp_add,Dept,min(Salary) as ‘lowest


salary’;

Output:

14
(ii) Maximum Salary:

Code: select Emp_id,Emp,name,Emp_add,Dept,max(Salary) as ‘highest


salary’;

Ouput:

(iii) Total Salary:

Code: select sum(Salary) from Emp;

Output:

15
(iv) Total Employees:

Code: select count(Emp_id) as ‘Total number of Employees’ from Emp;

Output:

(v) Average Salary:

Code: select avg(Salary) as ‘Average Salary’ from Emp;

Output:

MYSQL CONNECTOR/PYTHON
16
1.Question: Write a program to connect with database and store record of
employee and display records.

Aim: To Write a program to connect with database and store record of


employee and display records.

Program:

import mysql.connector as sql


mycon=sql.connect(host='localhost',user='root',passwd='*',database='schl')
if mycon.is_connected():
print("Connected to sql")
else:
print("error")
cursor=mycon.cursor()
s='select * from emp'
cursor.execute(s)
d=cursor.fetchall()
for row in d:
print(row)

Output:

Result:
The above program has been executed and the required output has been
obtained.

Display First 3 Rows

17
2.Question: Write a program to create student table which contains 5 students
details and display first three rows student table of MySQL database “test”.

Aim: To write a program to create student table which contains 5 students


details and display first three rows student table of MySQL database “test”.

Program:
import mysql.connector as sql
mycon=sql.connect(host='localhost',user='root',passwd='*',database='test')
if mycon.is_connected():
print("connected")
else:
print("error")
c=mycon.cursor()
s='select * from student'
c.execute(s)
data=c.fetchmany(3)
for row in data:
print(row)

Output:

Result:
The above program has been executed and the required output has been
obtained.

Search For a Record

18
3.Question: Write a program to connect with database and search employee
number in table employee and display record, if employee number not found,
displaying appropriate message.

Aim: To write a program to connect with database and search employee number
in table employee and display record, if employee number not found, displaying
appropriate message.

Program:
import mysql.connector as sql
mycon=sql.connect(host='localhost',user='root',passwd='darsh0104',database='s
chl')
if mycon.is_connected():
print("connected")
else:
print("error")

eid=input("enter employee id:")


s='select * from emp where Emp_id=(%s)'
t=(eid,)
cursor=mycon.cursor()
cursor.execute(s,t)
data=cursor.fetchall()
print(data)

Output:

Result:
The above program has been executed and the required output has been
obtained.

Update Into A Table

19
4. Question: Write a program to connect with database and update the
employee record related to the employee number entered by the user.

Aim: To write a program to connect with database and update the employee
record related to the employee number entered by the user.

Program:
import mysql.connector as sql
mycon=sql.connect(host='localhost',user='root',passwd='darsh0104',database='s
chl')
if mycon.is_connected():
print("connected")
else:
print("error")

eid=input("enter employee id:")


s='select * from emp where Emp_id=(%s)'
t=(eid,)
cursor=mycon.cursor()
cursor.execute(s,t)
data=cursor.fetchall()
print("Before updating:",data)

e=input("enter new department:")


s1='update emp set Dep=(%s) where Emp_id=(%s)'
t1=(e,eid)
cursor.execute(s1,t1)

s2='select * from emp where Emp_id=(%s)'


t=(eid,)
cursor=mycon.cursor()
cursor.execute(s,t)
data=cursor.fetchall()
print("After updating:",data)

Output:

20
Result:
The above program has been updated and the required output has been obtained.

Deleting Record

21
5.Question: Write a program to connect with database and delete the record of
the entered employee number.

Aim: To write a program to connect with database and delete the record of the
entered employee number.

Program:
import mysql.connector as sql
mycon=sql.connect(host='localhost',user='root',passwd='darsh0104',database='s
chl')
if mycon.is_connected():
print("connected")
else:
print("error")

eid=input("enter employee id:")


cursor=mycon.cursor()
s='select * from emp'
cursor.execute(s)
data=cursor.fetchall()
for row in data:
print(row)

s1='delete from emp where Emp_id=(%s)'


t1=(eid,)
cursor.execute(s1,t1)

s2='select * from emp'


cursor.execute(s)
d2=cursor.fetchall()
print("after updating:")
for row in d2:
print(row)

Output:

22
Result:
The above program has been executed and the required output has been
obtained.

23

You might also like