Download as pdf or txt
Download as pdf or txt
You are on page 1of 6

List of Practical’s for Term-2 Exam 2021-22

Class-XII
Subject: COMPUTER SCIENCE (083)

1. Design a python program to implement following stack operation using


list:
(i) Push Operation
(ii) Pop Operation
(iii) Peek Operation
(iv) Display Stack
(v) Exit

Ans:
def isEmpty(stk):
if stk==[]:
return True
else:
return False
def Push(stk,item):
stk.append(item)
top=len(stk)-1
def Pop(stk):
if isEmpty(stk):
return "Underflow"
else:
item=stk.pop()
if len(stk)==0:
top=None
else:
top=len(stk)-1
return item
def Peek(stk):
if isEmpty(stk):
return "Underflow"
else:
top=len(stk)-1
return stk[top]
def Display(stk):
if isEmpty(stk):
print("Empty Stack")
else:
top=len(stk)-1
print(stk[top],"<--top")
for a in range(top-1,-1,-1):
print(stk[a])
Stack=[]
top=None
while True:
print("STACK OPERATIONS:")
print("1.Push")
print("2.Pop")
print("3.Peek")
print("4.Display Stack")
print("5.Exit")
ch=int(input("Enter your choice (1-5):"))
if ch==1:
item=int(input("Enter item:"))
Push(Stack,item)
elif ch==2:
item=Pop(Stack)
if item=="Underflow":
print("Underflow ! Stack is Empty")
else:
print("Popped item is: ",item)
elif ch==3:
item=Peek(Stack)
if item=="Underflow":
print("Underflow ! Stack is Empty")
else:
print("Top most item is:",item)
elif ch==4:
Display(Stack)
elif ch==5:
break
else:
print("Invalid choice:")
Output:
STACK OPERATIONS:
1.Push
2.Pop
3.Peek
4.Display Stack
5.Exit
Enter your choice (1-5):1
Enter item:40
STACK OPERATIONS:
1.Push
2.Pop
3.Peek
4.Display Stack
5.Exit
Enter your choice (1-5):4
40 <--top
25
STACK OPERATIONS:
1.Push
2.Pop
3.Peek
4.Display Stack
5.Exit
Enter your choice (1-5):1
Enter item:30
STACK OPERATIONS:
1.Push
2.Pop
3.Peek
4.Display Stack
5.Exit
Enter your choice (1-5):3
Top most item is: 30
STACK OPERATIONS:
1.Push
2.Pop
3.Peek
4.Display Stack
5.Exit
Enter your choice (1-5):2
Popped item is: 30
STACK OPERATIONS:
1.Push
2.Pop
3.Peek
4.Display Stack
5.Exit
Enter your choice (1-5):4
40 <--top
25
STACK OPERATIONS:
1.Push
2.Pop
3.Peek
4.Display Stack
5.Exit
Enter your choice (1-5):5
>>>
PART-B : Database Management(MySQL) :

Table: Student
Sid Name City Marks
S5 KUINKA MORENA 53.6
S1 MONIKA GWALIOR 83.5
S2 RANJEET RANCHI 78.6
S3 JOHN ENGLAND 82.4
S4 ANSHIKA PATNA 68.2
S6 HARISH SHILONG 92.7

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

Mysql> create table student(sid char(5) not null primary key, name
char(15),city char(16),marks decimal(5,2));
Query OK, 0 rows affected (0.28 sec)

2. Write a query to insert the details of a new


student(„S5‟,‟KUINKA‟,‟MORENA‟,53.6) in the above table.
Mysql> insert into student values('S5','KUINKA','MORENA',53.6);
Query OK, 1 row affected (0.13 sec)

3. Write a query to delete the details of a student in the above table


.
Mysql> delete from student where sid=‟s2‟;

4. Write a query to display the details of the students with marks more than 80

Mysql> select * from student where marks>80;

5. Write a query to find the min, max, sum, and average of the marks in a
student table.

Mysql> select min(marks),max(marks),sum(marks),avg(marks) from


student;

6. Write a query to find the total number of students from each city in the table
Customer (SID, Name, City) using group by.

Mysql> select city,count(*) from student group by city;

7. Write a query to display the (student ID, marks) table in descending order of
the marks.

Mysql> select sid, marks from student order by marks desc;

8. Write a query to display the number of students with same class.

Mysql> select class,count(*) from student group by class;

9. Write a query to display the class where the number of student is less than 3
from student table.

mysql> select class,count(*) from student group by class having count(*)<3;

10. Write a query to display the Sum, Average, Highest and Lowest marks of
the students grouped by class.

mysql> select Class,sum(Marks),avg(Marks),max(Marks),min(Marks) from


student Group by class;
11.Write a query to display the number of students city wise.

mysql> select city,count(*) from student group by city;

12. Write a query to display names „MR. OBAMA and „MS. Gandhi‟ into
lower case.

mysql> select lcase('MR. OBAMA'),Lcase('MS. Gandhi');

13.Write a query to display 4 characters extracted from 3rd left character


onwards from string “ABCDEFG”.

mysql> select substr('ABCDEFG',3);

14. Write a query to count the number of characters are there in string
“CANDIDATE”.

mysql> SELECT LENGTH('CANDIDATE');

15.Write a query to delete the details of a student (”KUINKA”) from the


student table.

mysql> DELETE FROM STUDENT WHERE NAME='KUINKA';

***********************

You might also like