In this article, I will provide you solution with the Term 2 Practical file computer science class 12. According to the termwise syllabus for a computer science class 12, the practical file should be submitted in term 2. Let’s talk about the structure of practical assessment, here we go!

Term 2 Practical file Computer Science Class 12

The practical assessment of Computer since class 12 is as follows:

S.NoComponentMarks
1Lab Test6
1. Python Program 2
2. 3 SQL Queries based on one/two table(s), 2 output questions based on SQL queries 4
2Practical File3
1. Minimum 3 Python programs based on Term-2 Syllabus – Data Structure
2. SQL Queries – Minimum 5 sets using one table / two tables.
3. Minimum 2 programs based on Python – SQL connectivity.
3Project5
1. Term – 2: Final coding + Viva-voce
(Students will be allowed to modify their Term 1 document and submit the final executable code.)
4Viva Voce1

3 Parts of Term 2 Practical file computer science class 12

The first section of term Term 2 Practical file computer science class 12 consists of 3 programs from data structure topic.

Part A: 3 programs on data structure stack

[1] Write a menu-driven python program to implement stack operation.

def check_stack_isEmpty(stk):
    if stk==[]:
        return True
    else:
        return False
s=[] # An empty list to store stack elements, initially its empty
top = None # This is top pointer for push and pop operation
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:
           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]

Output

Download Term 2 Practical file computer science class 12 with complete solution

[2] Write a program to implement a stack for the employee details (empno, name).

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()
    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()
    else:
      print("Invalid Choice")

Download Term 2 Practical file computer science class 12 with complete solution

[3] Write a python program to check whether a string is a palindrome or not using stack.

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

# Function that returns 1 if string is a palindrome
def isPalindrome(string):
	global stack
	length = len(string)

	# Allocating the memory for the stack
	stack = ['0'] * (length + 1)

	# Finding the mid
	mid = length // 2
	i = 0
	while i < mid:
		push(string[i])
		i += 1

	# Checking if the length of the string is odd, if odd then neglect the middle character
	if length % 2 != 0:
		i += 1

	# While not the end of the string
	while i < length:
		ele = pop()

		# If the characters differ then the given string is not a palindrome
		if ele != string[i]:
			return False
		i += 1
	return True
string = input("Enter string to check:")

if isPalindrome(string):
        print("Yes, the string is a palindrome")
else:
        print("No, the string is not a palindrome")

Output:

Term 2 Practical file computer science class 12
Term 2 Practical file computer science class 12

Part B: 5 sets of SQL queries using one/two tables

In this section of Term 2 Practical file computer science class 12, 5 sets of SQL queries are required. These queries can be performed either on one or two tables. So here we go!

Queries Set 1 (Database Fetching records)

[1] Consider the following MOVIE table and write the SQL queries based on it.

Movie_IDMovieNameTypeReleaseDateProductionCostBusinessCost
M001The Kashmir FilesAction2022/01/2612450001300000
M002AttackAction2022/01/2811200001250000
M003Looop LapetaThriller2022/02/01250000300000
M004Badhai DoDrama2022/02/0472000068000
M005Shabaash MithuBiography2022/02/041000000800000
M006GehraiyaanRomance2022/02/11150000120000
  1. Display all information from movie.
  2. Display the type of movies.
  3. 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.
  4. Display movieid, moviename and productioncost for all movies with productioncost greater thatn 150000 and less than 1000000.
  5. Display the movie of type action and romance.
  6. Display the list of movies which are going to release in February, 2022.

Answers:

[1] select * from movie;

Output:

Download Term 2 Practical file computer science class 12 with complete solution

2. select distinct from a movie;

Download Term 2 Practical file computer science class 12 with complete solution

3. select movieid, moviename, productioncost + businesscost “total earning” from movie;

Download Term 2 Practical file computer science class 12 with complete solution

4. select movie_id,moviename, productioncost from movie where producst is >150000 and <1000000;

Download Term 2 Practical file computer science class 12 with complete solution

5. select moviename from movie where type =’action’ or type=’romance’;

Download Term 2 Practical file computer science class 12 with complete solution

6. select moviename from moview where month(releasedate)=2;

Download Term 2 Practical file computer science class 12 with complete solution

Queries Set 2 (Based on Functions)

  1. Write a query to display cube of 5.
  2. Write a query to display the number 563.854741 rounding off to the next hnudred.
  3. Write a query to display “put” from the word “Computer”.
  4. Write a query to display today’s date into DD.MM.YYYY format.
  5. Write a query to display ‘DIA’ from the word “MEDIA”.
  6. Write a query to display moviename – type from the table movie.
  7. Write a query to display first four digits of productioncost.
  8. Write a query to display last four digits of businesscost.
  9. Write a query to display weekday of release dates.
  10. Write a query to display dayname on which movies are going to be released.

Answers:

[1] select pow(5,3);

MySQL pow function

[2] select round(563.854741,-2);

Download Term 2 Practical file computer science class 12 with complete solution

[3] select mid(“Computer”,4,3);

MySQL mid function class 12 cs

[4] select concat(day(now()),concat(‘.’,month(now()),concat(‘.’,year(now())))) “Date”;

date functions and concat

[5] select right(“Media”,3);

Download Term 2 Practical file computer science class 12 with complete solution

[6] select concat(moviename,concat(‘ – ‘,type)) from movie;

joining two columns in mysql with separator

[7] select left(productioncost,4) from movie;

Download Term 2 Practical file computer science class 12 with complete solution

[8] select right(businesscost,4) from movie;

last digit from the number

[9] select weekday(releasedate) from movie;

weekday function in mysql

[10] select dayname(releasedate) from movie;

dayname in mysql

Queries Set 3 (DDL Commands)

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:

  1. Create a database “Sports”.
  2. Create a table “TEAM” with following considerations:
    • It should have a column TeamID for storing an integer value between 1 to 9, which refers to unique identification of a team.
    • Each TeamID should have its associated name (TeamName), which should be a string of length not less than 10 characters.
    • Using table level constraint, make TeamID as the primary key.
    • Show the structure of the table TEAM using a SQL statement.
    • As per the preferences of the students four teams were formed as given below. Insert these four rows in TEAM table:
      • Row 1: (1, Tehlka)
      • Row 2: (2, Toofan)
      • Row 3: (3, Aandhi)
      • Row 3: (4, Shailab)
    • Show the contents of the table TEAM using a DML statement.
  3. Now create another table MATCH_DETAILS and insert data as shown below. Choose appropriate data types and constraints for each attribute.
MatchIDMatchDateFirstTeamIDSecondTeamIDFirstTeamScoreSecondTeamScore
M12021/12/201210793
M22021/12/2134156158
M32021/12/22138681
M42021/12/23246567
M52021/12/24145288
M62021/12/25239768

Answers:

[1] create database sports

create database and use database command in my sql

[2] Creating table with the given specification

create table team
-> (teamid int(1),
-> teamname varchar(10), primary key(teamid));

Showing the structure of table using SQL statement:

desc team;
desc command in mysql

Inserting data:

mqsql> insert into team
    -> values(1,'Tehlka');
mysql insert command

Show the content of table – team:

select * from team;
select command in mysql

Creating another table:

create table match_details
    -> (matchid varchar(2) primary key,
    -> matchdate date,
    -> firstteamid int(1) references team(teamid),
    -> secondteamid int(1) references team(teamid),
    -> firstteamscore int(3),
    -> secondteamscore int(3));
create table with a foreign key in mysql
Download Term 2 Practical file computer science class 12 with complete solution

Queries set 4 (Based on Two Tables)

  1. Display the matchid, teamid, teamscore whoscored more than 70 in first ining along with team name.
  2. Display matchid, teamname and secondteamscore between 100 to 160.
  3. Display matchid, teamnames along with matchdates.
  4. Display unique team names
  5. Display matchid and matchdate played by Anadhi and Shailab.

Answers:

[1] 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;

Download Term 2 Practical file computer science class 12 with complete solution

[2] select matchid, teamname, secondteamscore from match_details, team where match_details.secondteamid=team.teamid and match_details.secondteamscore between 100 and 160;

join in mysql

[3] select matchid,teamname,firstteamid,secondteamid,matchdate from match_details, team where match_details.firstteamid=team.teamid;

join 3

[4] select distinct(teamname) from match_details, team where match_details.firstteamid=team.teamid;

distinct keyword in mysql

[5] select matchid,matchdate from match_details, team where match_details.firstteamid=team.teamid and team.teamname in (‘Aandhi’,’Shailab’);

Download Term 2 Practical file computer science class 12 with complete solution

Queries Set 5 (Group by , Order By)

Consider the following table stock table to answer the queries:

itemnoitemdcodeqtyunitpricestockdate
S005Ballpen102100102018/04/22
S003Gel Pen101150152018/03/18
S002Pencil10212552018/02/25
S006Eraser10120032018/01/12
S001Sharpner10321052018/06/11
S004Compass10260352018/05/10
S009A4 Papers10216052018/07/17
  1. Display all the items in the ascending order of stockdate.
  2. Display maximum price of items for each dealer individually as per dcode from stock.
  3. Display all the items in descending orders of itemnames.
  4. Display average price of items for each dealer individually as per doce from stock which avergae price is more than 5.
  5. Diisplay the sum of quantity for each dcode.

[1] select * from stock order by stockdate;

order by in my sql

[2] select dcode,max(unitprice) from stock group by code;

Download Term 2 Practical file computer science class 12 with complete solution

[3] select * from stock order by item desc;

use of order by desc in mysql

[4] select dcode,avg(unitprice) from stock group by dcode having avg(unitprice)>5;

Download Term 2 Practical file computer science class 12 with complete solution

[5] select dcode,sum(qty) from stock group by dcode;

Download Term 2 Practical file computer science class 12 with complete solution

Part C: SQL Database Connectivity 2 Programs

  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:
      • Insert two records in it
      • 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)

#Function to create Table
def c_table():
  try:
    c.execute('''create table students
    (
    rollno int(3),
    stname varchar(20)
    );
    ''')
    print("Table created successfully")
  except Exception as a:
    print("Create Table Error",a)

#Function to Insert Data
def e_data():
  try:
    while True:
      rno=int(input("Enter student rollno="))
      name=input("Enter student name=")
      c.execute("use {}".format('school'))
      c.execute("insert into students values({},'{}');".format(rno,name))
      db.commit()
      choice=input("Do you want to add more record<y/n>=")
      if choice in "Nn":
        break
  except Exception as a:
    print("Insert Record Error",a)

#Function to Display Data
def d_data():
  try:
    c.execute("select * from students")
    data=c.fetchall()
    for i in data:
      print(i)
  except Exception as a:
    print("Display Record 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
  else:
    print("Wrong option selected")
Download Term 2 Practical file computer science class 12 with complete solution
Download Term 2 Practical file computer science class 12 with complete solution

[2] using mysqlconnector

import mysql.connector as ms
db=ms.connect(host="localhost",user="root",passwd="root",database='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")
  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")

Watch the video for more understanding:

Download the term 2 practical files for computer science class 12, Term 2 Practical file computer science class 12 by following this link:

Term 2 Practical file computer science class 12

3 thoughts on “Download Term 2 Practical file computer science class 12 with complete solution”
  1. Please post the latest Practical programs as per CBSE 2022-23 syllabus.

    Thank You

Leave a Reply