Term 2 CS Practical File 2021-22
Term 2 CS Practical File 2021-22
Term 2 CS Practical File 2021-22
Term-II
Computer Science New (083)
Practical Record File
OF
AISSCE EXAMINATION SESSION 2021-22
SUBMITTED BY:
HOD(COMPUTER): VIKAS CHAHAL
CLASS: XI 'A'
ROLL NO:
Page 1
ACKNOWLEDGEMENT
[Name of Student]
Page 2
CERTIFICATE
supervision.
Page 3
No. Practical Date Signature
Write a menu-driven python program to implement stack
1
operation.
2 Write a program to implement a stack for the employee details
(empno, name).
3 Write a python program to check whether a string is a
palindrome or not using stack.
4 Queries Set 1 (Database Fetching records)
5 Queries Set 2 (Based on Functions)
6 Queries Set 3 (DDL Commands)
7 Queries set 4 (Based on Two Tables)
8 Queries Set 5 (Group by , Order By)
9 Write a MySQL connectivity program in Python to
Create a database school
Create a table students with the specifications -
ROLLNO integer, STNAME character(10) in MySQL
and perform the following operations:
o Insert two records in it
o Display the contents of the table
10 Perform all the operations with reference to table ‘students’
through MySQL-Python connectivity.
Page 4
Part A Data Structure
1. Write a menu-driven python program to implement stack operation.
Code:
def check_stack_isEmpty(stk):
if stk==[]:
return True
else:
return False
# An empty list to store stack elements, initially empty
s=[]
top = None # This is top pointer for push and pop
def main_menu():
while True:
print("Stack Implementation")
print("1 - Push")
print("2 - Pop")
print("3 - Peek")
print("4 - Display")
print("5 - Exit")
ch = int(input("Enter the your choice:"))
if ch==1:
el = int(input("Enter the value to push an
element:"))
push(s,el)
elif ch==2:
e=pop_stack(s)
if e=="UnderFlow":
print("Stack is underflow!")
else:
print("Element popped:",e)
elif ch==3:
e=pop_stack(s)
if e=="UnderFlow":
print("Stack is underflow!")
else:
print("The element on top is:",e)
elif ch==4:
Page 5
display(s)
elif ch==5:
break
else:
print("Sorry, You have entered invalid option")
def push(stk,e):
stk.append(e)
top = len(stk)-1
def display(stk):
if check_stack_isEmpty(stk):
print("Stack is Empty")
else:
top = len(stk)-1
print(stk[top],"-Top")
for i in range(top-1,-1,-1):
print(stk[i])
def pop_stack(stk):
if check_stack_isEmpty(stk):
return "UnderFlow"
else:
e = stk.pop()
if len(stk)==0:
top = None
else:
top = len(stk)-1
return e
def peek(stk):
if check_stack_isEmpty(stk):
return "UnderFlow"
else:
top = len(stk)-1
return stk[top]
Page 6
Output:
Page 7
2. Write a program to implement a stack for the employee details (empno, name).
Code:
stk=[]
top=-1
def line():
print('~'*100)
def isEmpty():
global stk
if stk==[]:
print("Stack is empty!!!")
else:
None
def push():
global stk
global top
empno=int(input("Enter the employee number to push:"))
ename=input("Enter the employee name to push:")
stk.append([empno,ename])
top=len(stk)-1
def display():
global stk
global top
if top==-1:
isEmpty()
else:
top=len(stk)-1
print(stk[top],"<-top")
for i in range(top-1,-1,-1):
print(stk[i])
def pop_ele():
global stk
global top
if top==-1:
isEmpty()
else:
stk.pop()
top=top-1
def main():
while True:
line()
Page 8
print("1. Push")
print("2. Pop")
print("3. Display")
print("4. Exit")
ch=int(input("Enter your choice:"))
if ch==1:nm
push()
print("Element Pushed")
elif ch==2:
pop_ele()
elif ch==3:
display()
elif ch==4:
break
else:
print("Invalid Choice")
Output:
Page 9
3. Write a python program to check whether a string is a palindrome or not using
stack.
Code:
stack = []
top = -1
# push function
def push(ele):
global top
top += 1
stack[top] = ele
# pop function
def pop():
global top
ele = stack[top]
top -= 1
return ele
Page 10
push(string[i])
i += 1
if isPalindrome(string):
print("Yes, the string is a palindrome")
else:
print("No, the string is not a palindrome")
Output:
Page 11
Part B sql queries
1. Consider the following MOVIE table and write the SQL queries based on it.
Movie_ID MovieName Type ReleaseDate ProductionCost BusinessCost
M001 The Kashmir Files Action 2022/01/26 1245000 1300000
M002 Attack Action 2022/01/28 1120000 1250000
M003 Looop Lapeta Thriller 2022/02/01 250000 300000
M004 Badhai Do Drama 2022/02/04 720000 68000
M005 Shabaash Mithu Biography 2022/02/04 1000000 800000
M006 Gehraiyaan Romance 2022/02/11 150000 120000
a) Display all information from movie.
b) Display the type of movies.
c) Display movieid, moviename, total_eraning by showing the business done by the
movies. Claculate the business done by movie using the sum of productioncost and
businesscost.
d) Display movieid, moviename and productioncost for all movies with
productioncost greater thatn 150000 and less than 1000000.
e) Display the movie of type action and romance.
f) Display the list of movies which are going to release in February, 2022.
Answers:
a) select * from movie;
Page 12
b) select distinct from a movie;
Page 13
f) select moviename from moview where month(releasedate)=2;
b) select round(563.854741,-2);
Page 14
c) select mid("Computer",4,3);
e) select right("Media",3);
Page 15
h) select right(businesscost,4) from movie;
3. Suppose your school management has decided to conduct cricket matches between
students of Class XI and Class XII. Students of each class are asked to join any one
of the four teams – Team Titan, Team Rockers, Team Magnet and Team
Hurricane. During summer vacations, various matches will be conducted between
these teams. Help your sports teacher to do the following:
a) Create a database “Sports”.
b) Create a table “TEAM” with following considerations:
a. It should have a column TeamID for storing an integer value between 1 to 9,
which refers to unique identification of a team.
b. Each TeamID should have its associated name (TeamName), which should be a
string of length not less than 10 characters.
c. Using table level constraint, make TeamID as the primary key.
Page 16
c) Show the structure of the table TEAM using a SQL statement.
d) As per the preferences of the students four teams were formed as given below. Insert
these four rows in TEAM table:
a. Row 1: (1, Tehlka)
b. Row 2: (2, Toofan)
c. Row 3: (3, Aandhi)
d. Row 3: (4, Shailab)
e) Show the contents of the table TEAM using a DML statement.
f) Now create another table MATCH_DETAILS and insert data as shown below. Choose
appropriate data types and constraints for each attribute.
Answers:
c) desc team;
Page 17
Inserting data:
Page 18
4. Write following queries:
a) Display the matchid, teamid, teamscore whoscored more than 70 in first ining
along with team name.
b) Display matchid, teamname and secondteamscore between 100 to 160.
c) Display matchid, teamnames along with matchdates.
d) Display unique team names
e) Display matchid and matchdate played by Anadhi and Shailab.
Answers:
a) select match_details.matchid, match_details.firstteamid,
team.teamname,match_details.firstteamscore from
match_details, team where match_details.firstteamid =
team.teamid and match_details.first
Page 19
b) select match_details.matchid, match_details.firstteamid,
team.teamname,match_details.firstteamscore from
match_details, team where match_details.firstteamid =
team.teamid and match_details.firstteamscore>70;
Page 20
5. Consider the following table and write the queries:
Page 21
b) select dcode,max(unitprice) from stock group by code;
Page 22
Part C Python Database connectivity
1. Write a MySQL connectivity program in Python to
Create a database school
Create a table students with the specifications - ROLLNO integer, STNAME
character(10) in MySQL and perform the following operations:
o Insert two records in it
o Display the contents of the table
2. Perform all the operations with reference to table ‘students’ through MySQL-Python
connectivity.
Answers:
1. Using pymysql - Code:
import pymysql as ms
#Function to create Database as per users choice
def c_database():
try:
dn=input("Enter Database Name=")
c.execute("create database {}".format(dn))
c.execute("use {}".format(dn))
print("Database created successfully")
except Exception as a:
print("Database Error",a)
#Function to Drop Database as per users choice
def d_database():
try:
dn=input("Enter Database Name to be dropped=")
c.execute("drop database {}".format(dn))
print("Database deleted sucessfully")
except Exception as a:
print("Database Drop Error",a)
db=ms.connect(host="localhost",user="root",password="root")
c=db.cursor()
while True:
print("MENU\n1. Create Database\n2. Drop Database \n3.
Create Table\n4. Insert Record \n5. Display Entire Data\n6.
Exit")
choice=int(input("Enter your choice<1-6>="))
if choice==1:
c_database()
elif choice==2:
d_database()
elif choice==3:
c_table()
elif choice==4:
e_data()
elif choice==5:
d_data()
elif choice==6:
break
Page 24
else:
print("Wrong option selected")
Output:
Page 25
2. using mysqlconnector
import mysql.connector as ms
db=ms.connect(host="localhost",user="root",passwd="root",datab
ase='school')
cn=db.cursor()
def insert_rec():
try:
while True:
rn=int(input("Enter roll number:"))
sname=input("Enter name:")
marks=float(input("Enter marks:"))
gr=input("Enter grade:")
cn.execute("insert into students
values({},'{}',{},'{}')".format(rn,sname,marks,gr))
db.commit()
ch=input("Want more records? Press (N/n) to stop
entry:")
if ch in 'Nn':
break
except Exception as e:
print("Error", e)
def update_rec():
try:
rn=int(input("Enter rollno to update:"))
marks=float(input("Enter new marks:"))
gr=input("Enter Grade:")
cn.execute("update students set marks={},grade='{}'
where rno={}".format(marks,gr,rn))
db.commit()
except Exception as e:
print("Error",e)
def delete_rec():
try:
rn=int(input("Enter rollno to delete:"))
cn.execute("delete from students where
rno={}".format(rn))
db.commit()
except Exception as e:
print("Error",e)
def view_rec():
try:
cn.execute("select * from students")
Page 26
except Exception as e:
print("Error",e)
while True:
print("MENU\n1. Insert Record\n2. Update Record \n3. Delete
Record\n4. Display Record \n5. Exit")
ch=int(input("Enter your choice<1-4>="))
if ch==1:
insert_rec()
elif ch==2:
update_rec()
elif ch==3:
delete_rec()
elif ch==4:
view_rec()
elif ch==5:
break
else:
print("Wrong option selected")
Output:
Page 27
Page 28
Page 29