0% found this document useful (0 votes)
73 views

Class XII Practical File 2023-24

The document acknowledges and thanks various people for their support and guidance in completing a practical project. It first thanks God for allowing the successful completion of the project. It then thanks the principal and computer science teacher for their valuable guidance that helped patch and make the project a full proof success. Finally, it thanks the author's parents for their valuable suggestions and guidance throughout the various phases of completing the project.
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
73 views

Class XII Practical File 2023-24

The document acknowledges and thanks various people for their support and guidance in completing a practical project. It first thanks God for allowing the successful completion of the project. It then thanks the principal and computer science teacher for their valuable guidance that helped patch and make the project a full proof success. Finally, it thanks the author's parents for their valuable suggestions and guidance throughout the various phases of completing the project.
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 34

ACKNOWLEDGEMENT

In the accomplishment of this practical successfully, many people have


best owned upon me their blessings and the heart pledge support, this time
I am utilising to thank all the people who have been concerned with this
practical.
Primarily I would like to thank god for being able to complete this project
with success. Then I would like to thank my Principal Ms.pratiba mam
and my Computer Science teacher Mr. Vivek Sir whose valuable
guidance has been the ones that helped me patch this practical and make it
full proof success ,their suggestion and instructions has served as the
major contribution towards the completion of this practical.
Then I would like to thank my parents who have helped me with their
valuable suggestion and guidance has been very helpful in various phases
of the completion of the practical
CERTIFICATE
This is to certify that Priyanshu sharma student of
class 12th has completed the research on the below
mentioned practical under the guidance of Mr. vivek
sir during the year of 2023-24 in partial fulfillment of
Computer Science practical examination conducted by
Noida Public School ,Noida.

________________ ________________
Signature of Internal Examiner Signature of External Examiner
INDEX
S.no Practical Date Signature

1. Write a program to implement


stack using a list-data structures.

2. Write a menu driven program to


push book no in stack and pop it
from stack.

3. Read a text file and display the no.


of vowels, consonant, upper case,
lower case and character.

4. Create a Binary file with name,


roll no search for a given roll no
and display the name if not found
print inappropriate message.

5. Create a binary file with roll no,


name and marks input the roll no
and update the marks.

6. Remove all the lines that contain “a”


in a file and write into another file
7. Write a random number
generator that generates random
number between 1 and 6 (rolling
of dice).

8. Write a query to display “put”


from the word “computer”

9. Write a query to display today’s


date into DD.MM.YYYY format

10. Write a query to display ‘DIA’


from the word ‘MEDIA’.

11. Create a database sports and


create table team with two
columns TEAMID &TEAMNAME.

12. Create a table Match Details.

13. Based on the above tables TEAM


& Match details write query for
the questions.

14. From the table movies given


below answer the following
questions.

15. Consider the following table stock


table to answer the queries

16. Write a program to connect


python to my SQL and insert
values to a existing table.

17. Create a menu driven program to


perform different functions by
python SQL connectivity.

Q1. Write a program to implement a stack using a list-data structure

#wap to implement a stack using a list-data structures

def push():

a=int(input('enter the element to be added'))

stack.append(a)

return a

def pop():

if stack==[]:

print('stack underflow')
else:

print('deleted element is:',stack.pop())

def display():

if stack==[]:

print('stack is empty!')

else:

for i in range(len(stack)-1,-1,-1):

print(stack[i])

stack=[]

print('STACK OPERATIONS')

choice='y'

while choice=='y':

print('1.PUSH')

print('2.POP')

print('3.DISPLAY')

c=int(input('enter your choice:'))

if c==1:

push()

elif c==2:

pop()

elif c==3:

display()
else:

print('wrong input')

choice=input('do yo want to continue or not?(y/n):')

OUTPUT:

Q2.Write a menu driven program to push book no in stack and popit from stack.

#Write a menu driven program to push book no in stack and pop it from stack

stk=[]

ch='Y'

while(ch=='Y' or ch=='y'):

print('enter 1: push')

print('enter 2: pop')

opt=int(input('enter your choice:='))


if opt==1:

d=int(input('enter book no:'))

stk.append(d)

print('item appended')

elif opt==2:

if (stk==[]):

print('stack empty')

else:

p=stk.pop()

print('deleted element:',p)

else:

print('invalid choice')

ch=(input('want to continue?'))

OUTPUT:
Q3. Read a text file and display the no. of vowels, consonant , upper case
, lower case and character
def cnt():

f=open("test2.txt","r")

cont=f.read()

print(cnt)

v=0

cons=0

l_c_l=0

u_c_l=0

for ch in cont:

if (ch.islower()):
l_c_l+=1

elif(ch.isupper()):

u_c_l+=1

ch=ch.lower()

if( ch in ['a','e','i','o','u']):

v+=1

elif (ch in ['b','c','d','f','g',

'h','j','k','l','m',

'n','p','q','r','s',

't','v','w','x','y','z']):

cons+=1

f.close()

print("Vowels are : ",v)

print("consonants are : ",cons)

print("Lower case letters are : ",l_c_l)

print("Upper case letters are : ",u_c_l)

#main program

cnt()

OUTPUT:
Q4. Create a Binary file with name, roll no search for a given roll no and display the
name if not found print inappropriate message.
import pickle
import sys
dict={}
def write_in_file():
file=open("D:\\stud2.dat","ab") #a-append,b-binary
no=int(input("ENTER NO OF STUDENTS: "))
for i in range(no):
print("Enter details of student ", i+1)
dict["roll"]=int(input("Enter roll number: "))
dict["name"]=input("enter the name: ")
pickle.dump(dict,file) #dump-to write in student file
file.close()

def display():
#read from file and display
file=open("D:\\stud2.dat","rb") #r-read,b-binary
try:
while True:
stud=pickle.load(file) #write to the file
print(stud)
except EOFError:
pass
file.close()

def search():
file=open("D:\\stud2.dat","rb") #r-read,b-binary
r=int(input("enter the rollno to search: "))
found=0
try:
while True:
data=pickle.load(file) #read from file
if data["roll"]==r:
print("The rollno =",r," record found")
print(data)
found=1
break
except EOFError:
pass
if found==0:
print("The rollno =",r," record is not found")
file.close()

#main program

while True:
print("MENU \n 1-Write in a file \n 2-display ")
print(" 3-search\n 4-exit \n")
ch=int(input("Enter your choice = "))
if ch==1:
write_in_file()
if ch==2:
display()
if ch==3:
search()
if ch==4:
print(" Thank you ")
sys.exit()

OUTPUT:
Q5. Create a binary file with roll no , name and marks input the roll no and update
the marks.
import pickle
#creating the file and writing the data
f=open("records.dat", "wb")
#list index 0 = roll number
#list index 1 = name
#list index 2 = marks
pickle.dump([1, "harshit", 90], f)
pickle.dump([2, "Tanish", 80], f)
pickle.dump([3, "Priyashi", 90], f)
pickle.dump([4, "rudra", 80], f)
pickle.dump([5, "Ashutosh", 85], f)
f.close()

#opeining the file to read contents


f=open("records.dat", "rb")
roll=int(input("Enter the Roll Number: "))
marks=float(input("Enter the updated marks: "))
List = [ ] #empty list
flag = False #turns to True if record is found
while True:
try:
record=pickle.load(f)
List.append(record)
except EOFError:
break
f.close()

#reopening the file to update the marks


f=open("records.dat", "wb")
for rec in List:
if rec[0]==roll:
rec[2] = marks
pickle.dump(rec, f)
print("Record updated successfully")
flag = True
else:
pickle.dump(rec,f)
f.close()
if flag==False:
print("This roll numer does not exist")

OUTPUT:

Q6. Remove all the lines that contain “a” in a file and write into another file.

fo=open("hp.txt","w")

fo.write("Harry Potter")

fo.write("There is a difference in all harry potter books\nWe can see it as harry


grows\nthe books were written by J.K rowling ")

fo.close()
fo=open('hp.txt','r')

fi=open('writehp.txt','w')

l=fo.readlines()

for i in l:

if 'a' in i:

i=i.replace('a','')

fi.write(i)

fi.close()

fo.close()

Output:
Q7. Write a random number generator that generates random number between 1 and
6 (rolling of dice).
import random

min = 1

max = 6

roll_again = "y"

while roll_again == "y" or roll_again == "Y":

print("Rolling the dice...")

val = random.randint (min, max)

print("You get... :", val)

roll_again = input("Roll the dice again? (y/n)...")

OUTPUT:
Q8. Write a query to display “put” from the word “computer”.

Query-mysql> select mid('computer',4,3);

OUTPUT:

Q9. Write a query to display today’s date into DD.MM.YYYY FORMAT.

Query-select concat(day(now()),concat(‘.’,month(now()),concat(‘.’,year

(now()))))”date”;

OUTPUT-
Q10. Write a query to display ‘DIA’ from the word ‘MEDIA’.

OUTPUT:

Q11. Create a database sport and create a table team with two columns TEAMID &
TEAMNAME.

⮚ Query-CREATE DATABASE SPORTS;

⮚ USE SPORTS;
⮚ CREATE TABLE TEAM(TEAMID INT(1),TEAMNAME VARCHAR(10),PRIMARY
KEY(TEAMID));
⮚ INSERT INTO TEAM VALUE(1,'TEHLKA');

⮚ INSERT INTO TEAM VALUE(2,'TOOFAN');

⮚ INSERT INTO TEAM VALUE(3,'AANDHI');

⮚ SELECT*FROM TEAM;

OUTPUT-
12. Create another table Match Details.

⮚ Query- 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));
⮚ insert into match_details value('M1','2021-12-20','1','2','107','93');

⮚ insert into match_details value('M2','2021-12-21','3','4','156','158');

⮚ insert into match_details value('M3','2021-12-22','1','3','86','81');

⮚ insert into match_details value('M4','2021-12-23','2','4','65','67');

⮚ insert into match_details value('M5','2021-12-24','1','4','52','88');

⮚ insert into match_details value('M6','2021-12-25','2','3','97','68');

⮚ DESC MATCH_DETAILS;
OUTPUT-
Q13. Based on the above two tables Team and Match_details answer the following
question.
1)display the matched,teamid,teamscore who scored more than 70 in first inning
along with team name.

⮚ select
match_details.matchid,match_details.firstteamid,team.teamname,match_de
tails.firstteamscore from match_details,team where
match_details.firstteamid=team.teamid and
match_details.firstteamscore>70;

OUTPUT-
2)Display matched,teamname and secondteamscore between 100 to 160.

⮚ select matchid,teamname,secondteamscore from match_details,team where


match_details.secondteamid=team.teamid and
⮚ -> match_details.secondteamscore between 100 and 160;

OUTPUT-
4)Display unique team names.

⮚ select distinct(teamname) from match_details,team where


match_details.firstteamid=team.teamid;

OUTPUT-

5)Display matched and matchdate played by aandhi and tehlka.

⮚ select matchid,matchdate from match_details,team where


match_details.firstteamid=team.teamid and team.teamname in
('AANDHI','tehlka');

OUTPUT-
Q14.From the table movies given below answer the following questions.

MOVIE_ID MOVIENAME TYPE Releasedate


M001 The Action 2022-01-26 1245000 1300000
Kashmir
files
M002 Attack Action 2022-01-28 1120000 1250000
M003 Loop Thriller 2022-02-01 250000 300000
lapeta
M004 Bdhai do Drama 2022-02-04 720000 4800000
M005 Shabaash Biography 2022-02-04 1000000 120000
Mothu
M006 Gehraiyaan Romance 2022-02-11 150000 800000

1)display all information from movies

⮚ Select * from movies


2) display all type of movies.

⮚ Select distinct from a movies;

3) display movieid,moviename,total_earning by showingthe business done by the


movies.calculate the business done by movie using sum of productioncost and
businesscost.

⮚ Select movie_id,moviename,productioncost+businessscost”total earning”


from movie;
4)Display movieid,moviename and productioncost for all movies with production
cost greater than 150000 and less than 1000000.

⮚ select movie_id,moviename,productioncost from movies where


productioncost>150000 and productioncost<1000000;

OUTPUT-

5)Display the movie of type action and romance

⮚ select moviename from movies where type='action'or type='romance';


OUTPUT-

Q15.Consider the following table stock table to answer the queries:

Itemno ITEM dcode Qty150 unitprice Stcokdate


S005 Ball pen 102 100 10 2018/04/22
S003 Gel pen 101 150 15 2018/03/18
S002 Pencil 102 125 5 2018/02/25
S006 Eraser 101 200 3 2018/01/12
S001 Sharpener 103 210 5 2012/06/11
S004 Compass 102 60 35 2018/05/10
S009 A4 papers 102 160 5 2018/07/17

1)DISPLAY ALL THE ITEMS IN ASCENDING ORDER OF STOCKDATE

⮚ SELECT *FROM ORDERBY ORDER BY STOCKDATE;

OUTPUT-
2)display maximum price of itmes for each dealer individually as per decode from
stock.

⮚ select dcode,max(unitprice) from orderby group by dcode;

OUTPUT-

3)display all the items in descending order of itemnames.

⮚ select * from orderby order by item desc;


OUTPUT-

4)Display average price of items for each dealer individually as per dcode from
orderby where average price is more than 5.

⮚ select dcode,avg(unitprice) from orderby group by dcode;

OUTPUT-
5)Display the sum of quantity for each dcode.

⮚ select dcode,avg(unitprice) from orderby group by dcode;

OUTPUT-

PYTHON –SQL CONNECTIVITY


Q16.write a program to connect python to mysql and insert value to a existing table.

⮚ import mysql.connector

⮚ con=mysql.connector.connect(host='localhost',user='root',password='may12
3@@',databse='sports')
⮚ cursor=con.cursor()

⮚ a="insert into orderby values('001','1000000','500','manager')"

⮚ cursor.execute(a)
⮚ con.commit()

⮚ con.close()

OUTPUT-

Q17.create a menu driven program to perform different functions by python sql


connectivity.

import mysql.connector
def show_databases():
mydb=mysql.connector.connect(host="localhost",user="root",password="sn
eha@123")
mycursor=mydb.cursor()
mycursor.execute("SHOW DATABASES")
for x in mycursor:
print(x)
def show_tables():
mydb=mysql.connector.connect(host="localhost",user="root",password="sn
eha@123",database="sports")
mycursor=mydb.cursor()
mycursor.execute("SHOW TABLES")
for x in mycursor:
print(x)
def create_table():

mydb=mysql.connector.connect(host="localhost",user="root",password="sn
eha@123",database="sports")
mycursor=mydb.cursor()
mycursor.execute("create table customers(name varchar(255),address
varchar(255))")
def insert_value():

mydb=mysql.connector.connect(host="localhost",user="root",password="sn
eha@123",database="sports")
mycursor=mydb.cursor()
a="insert into customers value('sneha','117-D,noida');"
mycursor.execute(a)
mydb.commit()
print(mycursor.rowcount,"record inserted.")
def display_value():

mydb=mysql.connector.connect(host="localhost",user="root",password="sn
eha@123",database="sports")
mycursor=mydb.cursor()
mycursor.execute("select * from customers")
myresult=mycursor.fetchall()
for x in myresult:
print(x)
#MAIN PROGRAM
while True:
print('''-----------
MENU
-----------''')
print(" List of choice")
print("1.")
print("2.")
print("3.")
print("4.")
print("5.")
ch=int(input("choose the function you want to perform"))
if ch==1:
show_databases()
elif ch==2:
show_tables()
elif ch==3:
create_table()
elif ch==4:
insert_value()
elif ch==5:
display_value()
else:
print("wrong option selected")

con=input("Do you want to continue?(y/n)")


if con=='Nn':
break
print("thank you")

OUTPUT:

You might also like